 
 									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

		forwardX11 = args['-forwardX11'] or (xserver is 'Xephyr')
		projectSrcDir = args['-projectSrcDir'] or '/home/jacob/workspace/scion'
		fileServerRoot = args['-fileServerRoot'] or "#{projectSrcDir}/build"

		console.log "received args",args



		finishedClients = []

		finish = ->
			console.error "All clients finished. Wrapping up."

			report =
				testCount : results.testCount
				testsPassed : result.id for result in results.testsPassed
				testsFailed : result.id for result in results.testsFailed
				testsErrored : result.id for result in results.testsErrored


			console.error report2string report

			endTime = new Date()

			console.error "Running time: #{(endTime - startTime)/1000} seconds"

			#TODO: kill processes, then exit
			#serverClientComm.killClientProcesses()

			process.exit results.testCount == results.testsPassed

		console.error "starting server"
		server = http.createServer (request,response) ->
			url = urlModule.parse request.url
