Explorar o código

[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 %!s(int64=2) %!d(string=hai) anos
pai
achega
699d7641b3
Modificáronse 1 ficheiros con 28 adicións e 17 borrados
  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 = "";
 		while (true) {
-			output += try {
+			final char = try {
 				String.fromCharCode(stdout.readByte());
 			} 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();
 			};
-			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");
 
-		var output = "";
-
+		final FDB_PROMPT = "(fdb) ";
 		// waits for the fdb prompt and runs a command
 		function runDebuggerCommand(command:String) {
-			output += readUntil(debuggerProcess.stdout, "(fdb) ") + '$command\n';
+			readUntil(debuggerProcess.stdout, FDB_PROMPT);
+			Sys.println(command);
 			debuggerProcess.stdin.writeString('$command\n');
 		}
 
 		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) {
 			case "Linux" if (ci == GithubActions):
 				new Process("xvfb-run", ["-a", playerLocation, swf]);
@@ -212,18 +224,17 @@ class Flash {
 				new Process(playerLocation, [swf]);
 		};
 
+		readUntil(debuggerProcess.stdout, "Player connected; session starting.", [FDB_PROMPT => onUnexpectedPrompt]);
 		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");
 
-		Sys.print(output);
-
 		debuggerProcess.kill();
 		debuggerProcess.close();
 		playerProcess.kill();