Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sdks
diff options
context:
space:
mode:
authorLarry Ewing <lewing@microsoft.com>2019-12-20 22:46:27 +0300
committerLarry Ewing <lewing@microsoft.com>2019-12-21 06:41:05 +0300
commit1587c49f5f593f9ca53ef5d46084c7b5c6b7d13a (patch)
treeeca9b038afbd792685c69ac394e699500177abf4 /sdks
parent14b736e9426ad975c54a99e3f04af091af0d48c3 (diff)
[wasm][debugger] Clean up startup and improve comments
Properly await more of the async logic and add retries when we get an empty response from the "json/list" endpoint.
Diffstat (limited to 'sdks')
-rw-r--r--sdks/wasm/ProxyDriver/TestHarnessStartup.cs65
1 files changed, 38 insertions, 27 deletions
diff --git a/sdks/wasm/ProxyDriver/TestHarnessStartup.cs b/sdks/wasm/ProxyDriver/TestHarnessStartup.cs
index 19a3bb9e95b..325781d9cb3 100644
--- a/sdks/wasm/ProxyDriver/TestHarnessStartup.cs
+++ b/sdks/wasm/ProxyDriver/TestHarnessStartup.cs
@@ -64,8 +64,9 @@ namespace WsProxy {
} catch (Exception e) { Console.WriteLine (e); }
}
- public async Task LaunchAndServe (ProcessStartInfo psi, HttpContext context, Func<string, string> extract_conn_url)
+ public async Task LaunchAndServe (ProcessStartInfo psi, HttpContext context, Func<string, Task<string>> extract_conn_url)
{
+
if (!context.WebSockets.IsWebSocketRequest) {
context.Response.StatusCode = 400;
return;
@@ -76,14 +77,20 @@ namespace WsProxy {
var proc = Process.Start (psi);
try {
proc.ErrorDataReceived += (sender, e) => {
- Console.WriteLine ($"stderr: {e.Data}");
- var res = extract_conn_url (e.Data);
- if (res != null)
- tcs.TrySetResult (res);
+ var str = e.Data;
+ Console.WriteLine ($"stderr: {str}");
+
+ if (str.Contains ("listening on", StringComparison.Ordinal)) {
+ var res = str.Substring (str.IndexOf ("ws://", StringComparison.Ordinal));
+ if (res != null)
+ tcs.TrySetResult (res);
+ }
};
+
proc.OutputDataReceived += (sender, e) => {
Console.WriteLine ($"stdout: {e.Data}");
};
+
proc.BeginErrorReadLine ();
proc.BeginOutputReadLine ();
@@ -91,7 +98,9 @@ namespace WsProxy {
Console.WriteLine ("Didnt get the con string after 2s.");
throw new Exception ("node.js timedout");
}
- var con_str = await tcs.Task;
+ var line = await tcs.Task;
+ var con_str = extract_conn_url != null ? await extract_conn_url (line) : line;
+
Console.WriteLine ($"lauching proxy for {con_str}");
var proxy = new MonoProxy ();
@@ -101,7 +110,7 @@ namespace WsProxy {
await proxy.Run (browserUri, ideSocket);
Console.WriteLine("Proxy done");
} catch (Exception e) {
- Console.WriteLine ("got exception {0}", e.GetType ().FullName);
+ Console.WriteLine ("got exception {0}", e);
} finally {
proc.CancelErrorRead ();
proc.CancelOutputRead ();
@@ -142,21 +151,27 @@ namespace WsProxy {
app.UseRouter (router => {
router.MapGet ("launch-chrome-and-connect", async context => {
Console.WriteLine ("New test request");
- await LaunchAndServe (psi, context, str => {
- //We wait for it as a signal that chrome finished launching
- if (!str.StartsWith ("DevTools listening on ", StringComparison.Ordinal))
- return null;
-
- // Unfortunately it does look like we have to wait
- // for a bit after getting the response but before
- // making the list request
- Thread.Sleep (500);
-
- var client = new HttpClient ();
- var res = client.GetStringAsync (new Uri (devToolsUrl, "/json/list")).Result;
- Console.WriteLine ("res is {0}", res);
- if (res == null)
- return null;
+ var client = new HttpClient ();
+ await LaunchAndServe (psi, context, async (str) => {
+ string res = null;
+ var start = DateTime.Now;
+
+ while (res == null) {
+ // Unfortunately it does look like we have to wait
+ // for a bit after getting the response but before
+ // making the list request. We get an empty result
+ // if we make the request too soon.
+ await Task.Delay (100);
+
+ res = await client.GetStringAsync (new Uri (new Uri (str), "/json/list"));
+ Console.WriteLine ("res is {0}", res);
+
+ var elapsed = DateTime.Now - start;
+ if (res == null && elapsed.Milliseconds > 2000) {
+ Console.WriteLine ($"Unable to get DevTools /json/list response in {elapsed.Seconds} seconds, stopping");
+ return null;
+ }
+ }
var obj = JArray.Parse (res);
if (obj == null || obj.Count < 1)
@@ -184,11 +199,7 @@ namespace WsProxy {
router.MapGet ("json/list", SendNodeList);
router.MapGet ("json/version", SendNodeVersion);
router.MapGet ("launch-done-and-connect", async context => {
- await LaunchAndServe (psi, context, str => {
- if (str.StartsWith ("Debugger listening on", StringComparison.Ordinal))
- return str.Substring (str.IndexOf ("ws://", StringComparison.Ordinal));
- return null;
- });
+ await LaunchAndServe (psi, context, null);
});
});
}