Browse Source

[ci] Follow up from #10999 (#11000)

* [ci] Constantly print flash debugger stdout

If something goes wrong and we don't reach the end, we will still see
the output

* [ci] Make flash tests more robust

If something unexpected happens, it should now quit the debugger instead
of continuing, which should stop it from hanging.

Also should be less likely for the debugger to fail to connect to the
player due to mistimed process calls.
tobil4sk 2 years ago
parent
commit
699d7641b3
1 changed files with 28 additions and 17 deletions
  1. 28 17
      tests/runci/targets/Flash.hx

+ 28 - 17
tests/runci/targets/Flash.hx

@@ -166,21 +166,26 @@ class Flash {
 		}
 		}
 	}
 	}
 
 
-	static function readUntil(stdout:haxe.io.Input, expected:String) {
+	static function readUntil(stdout:haxe.io.Input, expected:String, ?unexpectedStrings:Map<String, ()->Void>) {
+		final possibleStrings = unexpectedStrings?.copy() ?? [];
+		possibleStrings[expected] = function() {};
 		var output = "";
 		var output = "";
 		while (true) {
 		while (true) {
-			output += try {
+			final char = try {
 				String.fromCharCode(stdout.readByte());
 				String.fromCharCode(stdout.readByte());
 			} catch (e:haxe.io.Eof) {
 			} catch (e:haxe.io.Eof) {
-				failMsg('Expected to find "$expected". Output was:');
-				Sys.print(output);
+				failMsg('Expected to find "$expected" in stdout');
 				throw new CommandFailure();
 				throw new CommandFailure();
 			};
 			};
-			if (output.endsWith(expected)) {
-				break;
+			Sys.print(char);
+			output += char;
+			for (string => onMatch in possibleStrings) {
+				if (output.endsWith(string)) {
+					onMatch();
+					return;
+				}
 			}
 			}
 		}
 		}
-		return output;
 	}
 	}
 
 
 	/**
 	/**
@@ -193,16 +198,23 @@ class Flash {
 
 
 		final debuggerProcess = new Process("fdb");
 		final debuggerProcess = new Process("fdb");
 
 
-		var output = "";
-
+		final FDB_PROMPT = "(fdb) ";
 		// waits for the fdb prompt and runs a command
 		// waits for the fdb prompt and runs a command
 		function runDebuggerCommand(command:String) {
 		function runDebuggerCommand(command:String) {
-			output += readUntil(debuggerProcess.stdout, "(fdb) ") + '$command\n';
+			readUntil(debuggerProcess.stdout, FDB_PROMPT);
+			Sys.println(command);
 			debuggerProcess.stdin.writeString('$command\n');
 			debuggerProcess.stdin.writeString('$command\n');
 		}
 		}
 
 
 		runDebuggerCommand("run");
 		runDebuggerCommand("run");
 
 
+		function onUnexpectedPrompt() {
+			Sys.println("quit");
+			debuggerProcess.stdin.writeString("quit\n");
+			throw new CommandFailure();
+		}
+
+		readUntil(debuggerProcess.stdout, "Waiting for Player to connect", [FDB_PROMPT => onUnexpectedPrompt]);
 		final playerProcess = switch (systemName) {
 		final playerProcess = switch (systemName) {
 			case "Linux" if (ci == GithubActions):
 			case "Linux" if (ci == GithubActions):
 				new Process("xvfb-run", ["-a", playerLocation, swf]);
 				new Process("xvfb-run", ["-a", playerLocation, swf]);
@@ -212,18 +224,17 @@ class Flash {
 				new Process(playerLocation, [swf]);
 				new Process(playerLocation, [swf]);
 		};
 		};
 
 
+		readUntil(debuggerProcess.stdout, "Player connected; session starting.", [FDB_PROMPT => onUnexpectedPrompt]);
 		runDebuggerCommand("continue");
 		runDebuggerCommand("continue");
 
 
-		output += readUntil(debuggerProcess.stdout, "results: ");
-
-		final results = readUntil(debuggerProcess.stdout, "\n");
-		final success = results.contains("(success: true)");
-		output += results;
+		var success = true;
+		readUntil(debuggerProcess.stdout, "(success: true)", [
+			FDB_PROMPT => onUnexpectedPrompt,
+			"(success: false)" => () -> { success = false; }
+		]);
 
 
 		runDebuggerCommand("quit");
 		runDebuggerCommand("quit");
 
 
-		Sys.print(output);
-
 		debuggerProcess.kill();
 		debuggerProcess.kill();
 		debuggerProcess.close();
 		debuggerProcess.close();
 		playerProcess.kill();
 		playerProcess.kill();