public void RandomUrls() { ServerConfig options = new ServerConfig { TimeoutSeconds = 5 }; int outer = totalTests / simultaneousThreads; var list = GetRandomUrls(totalTests); List <string> successList = new List <string>(); List <string> failList = new List <string>(); int cur = 0; for (int i = 0; i < outer; i++) { IPromise[] promises = new IPromise[simultaneousThreads]; List <string> active = new List <string>(); for (int j = 0; j < simultaneousThreads; j++) { string url = list[cur++]; active.Add(url); promises[j] = CQ.CreateFromUrlAsync(url, options).Then((success) => { successList.Add(FormatResult(success)); active.Remove(success.Url); }, (fail) => { failList.Add(FormatResult(fail)); active.Remove(fail.Url); }); } if (!AsyncWebRequestManager.WaitForAsyncEvents(10000)) { AsyncWebRequestManager.CancelAsyncEvents(); foreach (var item in active) { failList.Add(item + ": aborted"); } } } Debug.WriteLine(FormatTestOutput(successList, failList)); }
/// <summary> /// Waits until all async events have completed. Use for testing primarily as a web app should /// not stop normally. /// </summary> /// /// <param name="timeout"> /// The maximum number of milliseconds to wait. /// </param> /// /// <returns> /// true if all events were cleared in the allotted time, false if not. /// </returns> public static bool WaitForAsyncEvents(int timeout = -1) { return(AsyncWebRequestManager.WaitForAsyncEvents(timeout)); }