public static void RunAsyncTest(IAsyncTest test, CancellationToken ct) { Console.WriteLine("# Running {0} ..."); using (var log = LogEnabled ? GetLogFile(test.Name) : null) { var db = GetLoggedDatabase(Db, log); var cts = CancellationTokenSource.CreateLinkedTokenSource(ct); try { var t = test.Run(db, log ?? Console.Out, cts.Token); t.GetAwaiter().GetResult(); Console.WriteLine("# Completed {0}.", test.Name); } catch (Exception e) { Console.Error.WriteLine("# {0} FAILED: {1}", test.Name, e.ToString()); } finally { cts.Dispose(); } } }
public async Task AsyncProxyWorks() { AsyncTest t = new AsyncTest(); IAsyncTest tp = AsyncFiberProxy <IAsyncTest> .Create(t); await tp.Init(); await tp.Add(1); await tp.Subtract(2); await Task.Delay(100); Assert.IsTrue(t.Inited); Assert.AreEqual(-1, t.Count); int result = 0; tp.Event1 += x => result = x; t.Trigger(); await Task.Delay(100); Assert.AreEqual(1, result); tp.Dispose(); Assert.IsTrue(t.Inited); Assert.AreEqual(-1, t.Count); Assert.IsTrue(t.Disposed); }
public void RunTestAsync(IAsyncTest instance, T test) { if (instance.GetMixinState <AsyncTestState>().UseLoadContext) { ExecuteInNewLoadContext(test); } else { RunTestAsync(ToFuncOfTask(test)); } }
public static void RunTestAsync(this IAsyncTest instance, Func <Task> testAsync) => new AsyncTestRunner().RunTestAsync(instance, testAsync);
public static void RunTest(this IAsyncTest instance, Action test) => new SyncTestRunner().RunTestAsync(instance, test);