5 Commits d18246eece ... c2bc1d2783

Author SHA1 Message Date
  Michael Buesch c2bc1d2783 Add EXAMPLE.awlpro to coreserver test 5 years ago
  Michael Buesch fdc2bd6127 tests/run: Make run_test single-core 5 years ago
  Michael Buesch 3f022c6e91 common/net: Set SO_REUSEADDR to allow binding to dying sockets 5 years ago
  Michael Buesch 7731c317a8 coreserver/coreclient: Force sockets to non-blocking on shutdown 5 years ago
  Michael Buesch 99d357e497 awlsim-test: Shut down tunnel after client 5 years ago

+ 2 - 2
awlsim-test

@@ -436,10 +436,10 @@ def runWithServerBackend(inputFile):
 	except KeyboardInterrupt as e:
 		pass
 	finally:
-		if tunnel:
-			tunnel.shutdown()
 		if client:
 			client.shutdown()
+		if tunnel:
+			tunnel.shutdown()
 	return ExitCodes.EXIT_OK
 
 def __signalHandler(sig, frame):

+ 2 - 1
awlsim/common/net.py

@@ -2,7 +2,7 @@
 #
 # AWL simulator - networking utility functions
 #
-# Copyright 2013-2016 Michael Buesch <m@bues.ch>
+# Copyright 2013-2018 Michael Buesch <m@bues.ch>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -85,6 +85,7 @@ def netPortIsUnused(host, port):
 				return True
 			return False
 		sock = socket.socket(family, socktype)
+		sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 		sock.bind(sockaddr)
 	except _SocketErrors as e:
 		return False

+ 2 - 0
awlsim/coreserver/messages.py

@@ -1305,6 +1305,8 @@ class AwlSimMessageTransceiver(object):
 	def shutdown(self):
 		if self.sock:
 			with suppressAllExc:
+				self.sock.setblocking(False)
+			with suppressAllExc:
 				self.sock.shutdown(socket.SHUT_RDWR)
 			with suppressAllExc:
 				self.sock.close()

+ 6 - 2
awlsim/coreserver/server.py

@@ -1414,6 +1414,8 @@ class AwlSimServer(object): #+cdef
 
 		if self.__socket:
 			with suppressAllExc:
+				self.__socket.setblocking(False)
+			with suppressAllExc:
 				self.__socket.shutdown(socket.SHUT_RDWR)
 			with suppressAllExc:
 				self.__socket.close()
@@ -1426,8 +1428,10 @@ class AwlSimServer(object): #+cdef
 
 	def shutdown(self):
 		printInfo("Shutting down.")
-		self.close()
-		self.__sim.shutdown()
+		with suppressAllExc:
+			self.close()
+		with suppressAllExc:
+			self.__sim.shutdown()
 
 	def signalHandler(self, sig, frame):
 		printInfo("Received signal %d" % sig)

+ 4 - 1
tests/800-coreserver/coreserver-cli.sh

@@ -7,10 +7,13 @@ sh_test()
 	infomsg
 	infomsg "--- Running coreserver tests"
 	cd "$rootdir" || die "Failed to change to rootdir '$rootdir'"
-	for testfile in 000-base/shutdown.awl; do
+
+	for testfile in 000-base/shutdown.awl \
+			000-base/EXAMPLE.awlpro; do
 		run_test "$interpreter" "$basedir/$testfile" \
 			--spawn-backend --interpreter "$interpreter" \
 			--connect-to localhost:$(get_port)
 	done
+
 	infomsg -n "--- Finished coreserver tests "
 }

+ 9 - 9
tests/run.sh

@@ -523,7 +523,7 @@ run_nose_test()
 }
 
 # $1=interpreter $2=testfile(.awl/.sh) ($3ff additional options to awlsim-test or testfile)
-__run_test()
+run_test()
 {
 	local interpreter="$1"
 	local testfile="$2"
@@ -565,15 +565,15 @@ __run_test()
 	fi
 }
 
-run_test()
+run_test_parallel()
 {
 	if is_parallel_run; then
 		# Run tests in parallel.
 		wait_for_free_job_slot
-		__run_test "$@" &
+		run_test "$@" &
 	else
 		# Run tests one-by-one.
-		__run_test "$@"
+		run_test "$@"
 	fi
 }
 
@@ -592,7 +592,7 @@ run_test_directory()
 		[ "$(echo -n "$entry" | tail -c7)" = ".awlpro" ] || continue
 		[ -e "$(dirname "$entry")/$(basename "$entry" .awlpro).sh" ] && continue
 
-		run_test "$interpreter" "$entry"
+		run_test_parallel "$interpreter" "$entry"
 		check_job_failure && return
 	done
 	# run .awl tests
@@ -602,21 +602,21 @@ run_test_directory()
 		[ -e "$(dirname "$entry")/$(basename "$entry" .awl).awlpro" ] && continue
 		[ -e "$(dirname "$entry")/$(basename "$entry" .awl).sh" ] && continue
 
-		run_test "$interpreter" "$entry"
+		run_test_parallel "$interpreter" "$entry"
 		check_job_failure && return
 	done
 	# run .sh tests
 	for entry in "$directory"/*; do
 		[ -d "$entry" ] && continue
 		[ "$(echo -n "$entry" | tail -c3)" = ".sh" ] || continue
-		run_test "$interpreter" "$entry"
+		run_test_parallel "$interpreter" "$entry"
 		check_job_failure && return
 	done
 	# run nose tests
 	for entry in "$directory"/*; do
 		[ -d "$entry" ] && continue
 		[ "$(echo -n "$entry" | tail -c3)" = ".py" ] || continue
-		run_test "$interpreter" "$entry"
+		run_test_parallel "$interpreter" "$entry"
 		check_job_failure && return
 	done
 	# Recurse into subdirectories
@@ -757,7 +757,7 @@ do_tests()
 				if [ -d "$opt" ]; then
 					run_test_directory "$interpreter" "$opt"
 				else
-					run_test "$interpreter" "$opt"
+					run_test_parallel "$interpreter" "$opt"
 				fi
 				check_job_failure && break
 			done