 
 									results.testsFailed.push testData.test
 
-									#test has failed, so we send reset event
-									serverClientComm.sendResetEventToClient testData.sourceAddress
+									#if stopOnFail is set, then wrap up
+									if stopOnFail
+										console.error "Test #{testData.test.id} failed and stopOnFail is set. Wrapping up..."
+										finish()
+									else
+										#if the event sending process is still active
+										if testData.sendEventProcess.pid
+											#wait for exit event
+											testData.sendEventProcess.on "exit", ->
+												serverClientComm.sendResetEventToClient testData.sourceAddress
+
+											#kill the event process
+											testData.sendEventProcess.kill()
+										else
+											#otherwise just wait for the reset event
+											serverClientComm.sendResetEventToClient testData.sourceAddress
+
 							catch e
 								console.error e.message
 								console.error e.type

								console.error "Cannot find testData with id #{o.id}"

							#send the events to the browser, via a proxy
							serverClientComm.sendEventsToBrowser testData.sourceAddress,testData.test.testScript.events.slice(),projectSrcDir

				when "/check-configuration"
					do ->

		console.log "forwardX11",forwardX11
		console.log "projectSrcDir",projectSrcDir
		console.log "fileServerRoot",fileServerRoot
		console.log "stopOnFail",stopOnFail

		serverTestRunnerUrl = "http://#{hostServerHostName}:#{hostServerPort}/runner"

