public async Task Start(IDictionary <string, List <string> > args) { await Task.Yield(); var ta = new TestArgs(args); var s = ta.AE; var t = ta.BE; var a = new XPU(new XCfg( new BeamerCfg() { Log = new BeamerLogCfg("a", ta.Log) }, new XLogCfg("a-SimpleExchange", ta.Log), new HeapHighway(ushort.MaxValue))); var b = new XPU(new XCfg( new BeamerCfg() { Log = new BeamerLogCfg("b", ta.Log) }, new XLogCfg("b-SimpleExchange", ta.Log), new HeapHighway(ushort.MaxValue))); const string ADD_ONE = "addOne"; try { b.RegisterAPI(ADD_ONE, add_one); a.Start(s, t); b.Start(t, s); await a.TargetIsActive(); await b.TargetIsActive(); using (var ix = await a.Request(ADD_ONE, 3)) if (!ix.IsOK || ix.Make <int>() != 4) { Passed = false; FailureMessage = "Request failure."; return; } Passed = true; IsComplete = true; } catch (Exception ex) { Passed = false; FailureMessage = ex.ToString(); } finally { a.Dispose(); b.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { #if !DEBUG && !ASSERT return; #endif await Task.Yield(); var ta = new TestArgs(args); var arg = new byte[100_000_000];
public async Task Start(IDictionary <string, List <string> > args) { var ta = new TestArgs(args); var s = ta.AE; var t = ta.BE; var a = new XPU(new XCfg( new BeamerCfg() { Log = new BeamerLogCfg("a", ta.Log) }, new XLogCfg("a-ResNotFound", ta.Log), new HeapHighway(ushort.MaxValue))); var b = new XPU(new XCfg( new BeamerCfg() { Log = new BeamerLogCfg("b", ta.Log) }, new XLogCfg("b-ResNotFound", ta.Log), new HeapHighway(ushort.MaxValue))); try { a.Start(s, t); b.Start(t, s); await a.TargetIsActive(); await b.TargetIsActive(); using (var ix = await a.Request("NonExistingResKey", 3)) if (!ix.IsOK && ix.ErrorCode == (int)XErrorCode.ResourceNotFound) { Passed = true; IsComplete = true; } if (!Passed.HasValue) { Passed = false; } } catch (Exception ex) { Passed = false; FailureMessage = ex.ToString(); } finally { a.Dispose(); b.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { var targ = new TestArgs(args); for (int i = 0; i < 4; i++) { await halfGigNoLogNoVerify(targ); } IsComplete = true; Passed = true; }
public async Task Start(IDictionary <string, List <string> > args) { var targ = new TestArgs(args); //await WithCheck(targ); await NoCheck(targ); if (!Passed.HasValue) { Passed = true; IsComplete = true; } }
async Task NoCheck(TestArgs targ) { int PULSE_RETENTION = new BeamerCfg().PulseRetentionMS; $"WithoutCheck, PulseRetentionMS: {PULSE_RETENTION}".AsInfo(); Beamer rayA = null; Beamer rayB = null; try { var done = new ResetEvent(false); var aep = targ.AE; var bep = targ.BE; const int BYTES_TO_TRANSFER = 100_000_000; const int MAX_RANDOM_SIZE = 1000; int totalSent = 0; int totalReceived = 0; rayA = new Beamer((f) => { }, new BeamerCfg() { EnablePulsing = true, Log = new BeamerLogCfg("rayA-PulseNoCheck", targ.Log) }); rayB = new Beamer((f) => { try { if (f == null || f.IsDisposed || f.Length < 1) { throw new Exception("Frag"); } var tr = Interlocked.Add(ref totalReceived, f.Length); if (tr >= BYTES_TO_TRANSFER) { done.Set(); } } catch (Exception ex) { ex.ToString().AsError(); } finally { if (f != null) { f.Dispose(); } } }, new BeamerCfg() { Log = new BeamerLogCfg("rayB-PulseNoCheck", targ.Log) }); var hw = new HeapHighway(); var ta = new Task(async() => { await Task.Yield(); rayA.LockOn(aep, bep); var rdm = new Random(); while (true) { try { if (done.Task.Status == TaskStatus.RanToCompletion) { return; } using (var f = hw.Alloc(rdm.Next(1, MAX_RANDOM_SIZE))) { rayA.Pulse(f); var ts = Interlocked.Add(ref totalSent, f.Length); if (ts >= BYTES_TO_TRANSFER) { break; } } } catch (Exception ex) { ex.Message.AsError(); } } rayA.trace("Out of pulsing", null); }); var tb = new Task(async() => { rayB.LockOn(bep, aep); }); ta.Start(); tb.Start(); if (await done.Wait() < 0) { Passed = false; FailureMessage = "Timeout"; } if (!Passed.HasValue) { "OK: WithoutCheck".AsSuccess(); } } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { rayA.Dispose(); rayB.Dispose(); } }
async Task WithCheck(TestArgs targ) { const int PULSE_RETENTION = 0; $"WithCheck, PulseRetentionMS: {PULSE_RETENTION}".AsInfo(); Beamer rayA = null; Beamer rayB = null; try { var done = new ResetEvent(false); var aep = targ.AE; var bep = targ.BE; const int BYTES_TO_TRANSFER = 10_000_000; const int MAX_RANDOM_SIZE = 1000; int totalSent = 0; int totalReceived = 0; rayA = new Beamer( (f) => { Console.WriteLine("?"); }, new BeamerCfg() { EnablePulsing = true, PulseRetentionMS = 0, Log = new BeamerLogCfg("rayA-PulseWithCheck", targ.Log) }); rayB = new Beamer((f) => { try { if (f == null || f.IsDisposed || f.Length < 1) { throw new Exception("Frag"); } var fs = f.Span(); var v = fs[0]; for (int i = 1; i < fs.Length; i++) { if (v != fs[i] || fs[i] == 0) { FailureMessage = "Received wrong data"; Passed = false; done.Set(false); } } var tr = Interlocked.Add(ref totalReceived, f.Length); //$"TR: {tr}".AsInfo(); if (tr >= BYTES_TO_TRANSFER) { done.Set(); } } catch (Exception ex) { ex.ToString().AsError(); } finally { if (f != null) { f.Dispose(); } } }, new BeamerCfg() { Log = new BeamerLogCfg("rayB-PulseWithCheck", targ.Log) }); using (var hw = new HeapHighway()) { var ta = new Task(async() => { await Task.Yield(); rayA.LockOn(aep, bep); var rdm = new Random(); while (true) { try { if (done.Task.Status == TaskStatus.RanToCompletion) { return; } using (var f = hw.Alloc(rdm.Next(1, MAX_RANDOM_SIZE))) { var v = (byte)rdm.Next(1, 255); for (int j = 0; j < f.Length; j++) { f[j] = v; } rayA.Pulse(f); var ts = Interlocked.Add(ref totalSent, f.Length); if (ts >= BYTES_TO_TRANSFER) { break; } } } catch (Exception ex) { } } }); var tb = new Task(() => { rayB.LockOn(bep, aep); }); ta.Start(); tb.Start(); if (await done.Wait() < 0) { Passed = false; FailureMessage = "Timeout"; } } if (!Passed.HasValue) { "OK: WithCheck".AsSuccess(); } } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { rayA.Dispose(); rayB.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { Beamer rayA = null; Beamer rayB = null; var rdmSize = new Random(); const int TOTAL_SENDS = 100; const int MIN_SIZE = 10_000; const int MAX_SIZE = 10_000_000; var rmask = new bool[TOTAL_SENDS]; var smask = new bool[TOTAL_SENDS]; try { var targ = new TestArgs(args); var rst = new CountdownEvent(TOTAL_SENDS); void receive(MemoryFragment f) { int len = 0; try { var s = f.Span(); f.Read(ref len, 0); if (s.Length == len) { rmask[f[4]] = true; for (int i = 4; i < len; i++) { if (f[i] != f[4]) { Passed = false; "Received incorrect data.".AsError(); break; } } } else { Passed = false; "rayB receive failed.".AsError(); } } catch (Exception ex) { Passed = false; ex.Message.AsError(); } finally { rst.Signal(); $"Signal {rst.CurrentCount}".AsInnerInfo(); } } rayA = new Beamer((f) => { }, new BeamerCfg() { Log = new BeamerLogCfg("rayA-ConcurrentBeams", targ.Log) { OnTrace = null }, }); rayB = new Beamer((f) => receive(f), new BeamerCfg() { Log = new BeamerLogCfg("rayB-ConcurrentBeams", targ.Log) { OnTrace = null }, }); var ta = new Task(async() => { await rayA.LockOn(targ.AE, targ.BE, -1); using (var hw = new HeapHighway()) { Parallel.For(0, TOTAL_SENDS, (i) => { try { if (rayA.IsStopped) { return; } var len = rdmSize.Next(MIN_SIZE, MAX_SIZE); using (var f = hw.Alloc(len)) { for (int j = 0; j < len; j++) { f[j] = (byte)i; } f.Write(len, 0); if (!rayA.Beam(f).Result) { "Failed to beam".AsError(); } } smask[i] = true; if (!hw.IsDisposed) { $"Lanes :{hw.GetLanesCount()} i:{i}".AsInfo(); } } catch (Exception ex) { ex.ToString().AsError(); } }); } $"Out of beaming loop".AsInnerInfo(); }); ta.Start(); if (!rayB.LockOn(targ.BE, targ.AE)) { $"Failed to lock on rayA".AsError(); } if (!rst.Wait(new TimeSpan(0, 4, 0))) { Passed = false; FailureMessage = "Timeout."; } if (rmask.Contains(false)) { Passed = false; FailureMessage = "Non received data"; } await Task.Yield(); if (!Passed.HasValue) { Passed = true; } IsComplete = true; } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { if (rayA != null) { rayA.Dispose(); } if (rayB != null) { rayB.Dispose(); } } }
public async Task Start(IDictionary <string, List <string> > args) { var ta = new TestArgs(args); var s = ta.AE; var t = ta.BE; var a = new XPU(new XCfg( new BeamerCfg() { Log = new BeamerLogCfg("a", ta.Log) }, new XLogCfg("a-RemoteException", ta.Log), new HeapHighway(ushort.MaxValue))); var b = new XPU(new XCfg( new BeamerCfg() { Log = new BeamerLogCfg("b", ta.Log) }, new XLogCfg("b-RemoteException", ta.Log), new HeapHighway(ushort.MaxValue))); try { string RES = "WillThrow"; b.RegisterAPI(RES, (f) => { "Throwing NotSupportedException".AsInfo(); throw new NotSupportedException(); }); a.Start(s, t); b.Start(t, s); await a.TargetIsActive(); await b.TargetIsActive(); using (var ix = await a.Request(RES)) if (!ix.IsOK && ix.ErrorCode == (int)XErrorCode.SerializedException) { var ex = ix.Make <Exception>(); if (ex is NotSupportedException) { Passed = true; IsComplete = true; } } if (!Passed.HasValue) { Passed = false; } } catch (Exception ex) { Passed = false; FailureMessage = ex.ToString(); } finally { a.Dispose(); b.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { #if !DEBUG && !ASSERT return; #endif Beamer rayA = null; Beamer rayB = null; const int CFGA = 11; const int CFGB = 12; try { var targ = new TestArgs(args); var aep = targ.AE; var bep = targ.BE; rayA = new Beamer((f) => { }, new BeamerCfg() { Log = new BeamerLogCfg("rayA-ConfigExchange", targ.Log), MaxBeamedTilesAtOnce = CFGA #if DEBUG , dropFrames = true, deopFramePercent = 50 #endif }); rayB = new Beamer((f) => { }, new BeamerCfg() { Log = new BeamerLogCfg("rayB-ConfigExchange", targ.Log), MaxBeamedTilesAtOnce = CFGB #if DEBUG , dropFrames = true, deopFramePercent = 50 #endif }); var ta = new Task(async() => { if (rayA.LockOn(aep, bep) && await rayA.ConfigRequest()) { // The remote config must be available here var tc = rayA.GetTargetConfig(); if (tc == null || tc.MaxBeamedTilesAtOnce != CFGB) { Passed = false; FailureMessage = "The remote config B is not correct or is missing."; } } }); var tb = new Task(async() => { if (rayB.LockOn(bep, aep) && await rayB.ConfigRequest()) { var tc = rayB.GetTargetConfig(); if (tc == null || tc.MaxBeamedTilesAtOnce != CFGA) { Passed = false; FailureMessage = "The remote config A is not correct or is missing."; } } }); ta.Start(); tb.Start(); if (!Task.WaitAll(new Task[] { ta, tb }, new TimeSpan(0, 2, 0))) { Passed = false; FailureMessage = "Timeout."; FailureMessage.AsError(); } await Task.Yield(); if (Passed.HasValue && !Passed.Value) { "configExchange() failed".AsError(); } else { "OK: configExchange()".AsSuccess(); Passed = true; } IsComplete = true; } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { rayA.Dispose(); rayB.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { var ta = new TestArgs(args); var s = ta.AE; var t = ta.BE; var a = new XPU(new XCfg( new BeamerCfg() { Log = new BeamerLogCfg("a", ta.Log) }, new XLogCfg("a-Replies", ta.Log), new HeapHighway(ushort.MaxValue))); var b = new XPU(new XCfg( new BeamerCfg() { Log = new BeamerLogCfg("b", ta.Log) }, new XLogCfg("b-Replies", ta.Log), new HeapHighway(ushort.MaxValue))); MarshalSlot ms = null; try { b.RegisterAPI("ep", entry_point); a.Start(s, t); b.Start(t, s); await a.TargetIsActive(); await b.TargetIsActive(); ms = MarshalSlot.Store(8); var x = await a.RawRequest("ep", ms, false, TIMEOUT); int data = 0; x.Fragment.Read(ref data, x.DataOffset); while (data > 0 && !x.DoNotReply) { data--; ms.Write(data, 0); x = await x.RawReply(ms, data < 1, true, TIMEOUT); if (!x.IsOK) { Passed = false; FailureMessage = "Timeout"; return; } if (x.State == XState.Beamed) { x.Fragment.Read(ref data, x.DataOffset); } } await Task.Delay(TIMEOUT.Milliseconds * 3); if (!Passed.HasValue) { Passed = true; IsComplete = true; } } catch (Exception ex) { Passed = false; FailureMessage = ex.ToString(); } finally { a.Dispose(); b.Dispose(); ms.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { #if !DEBUG && !ASSERT return; #endif Beamer rayA = null; Beamer rayB = null; const int CAP = 30_000_000; int totalSend = 0; int totalReceived = 0; int totalFragsOut = 0; int totalFragsIn = 0; var rdmSize = new Random(); // If b is on a remote machine var OVER = 7654321; try { var targ = new TestArgs(args); var rst = new ManualResetEvent(false); var aep = targ.AE; var bep = targ.BE; void receive(MemoryFragment f) { int len = 0; try { var s = f.Span(); f.Read(ref len, 0); var fi = Interlocked.Increment(ref totalFragsIn); if (s.Length == len) { for (int i = 4; i < len; i++) { if (f[i] != 43) { Passed = false; "rayB received incorrect data.".AsError(); break; } } var ts = Interlocked.Add(ref totalReceived, len); string.Format("R: {0, -10} TR: {1, -10} FI: {2, -3}", len, ts, fi).AsInnerInfo(); } else { Passed = false; "rayB receive failed.".AsError(); } } finally { if ((Passed.HasValue && !Passed.Value) || Volatile.Read(ref totalReceived) >= CAP) { if (!Passed.HasValue) { Passed = true; "OK: Send/Receive with dropped random frames on both sides.".AsSuccess(); } rst.Set(); } } } if (targ.A) { rayA = new Beamer( (f) => { // If using a remote, this is equivalent to rst.Set; var over = 0; f.Read(ref over, 0); if (OVER == over) { rst.Set(); } else { Passed = false; FailureMessage = $"rayA received unknown <over> signal."; } }, new BeamerCfg() { Log = new BeamerLogCfg("rayA-DroppingFrames30M", targ.Log) { OnTrace = null }, #if DEBUG || ASSERT dropFrames = true, deopFramePercent = 20 #endif }); } if (targ.B) { rayB = new Beamer(receive, new BeamerCfg() { Log = new BeamerLogCfg("rayB-DroppingFrames30M", targ.Log) { OnTrace = null }, #if DEBUG || ASSERT dropFrames = true, deopFramePercent = 20 #endif }); } using (var hw = new HeapHighway()) { if (targ.A) { var ta = new Task(async() => { await rayA.LockOn(aep, bep, -1); while (!rayA.IsStopped) { var len = rdmSize.Next(10, 1_000_000); var f = hw.Alloc(len); for (int i = 0; i < len; i++) { f[i] = 43; } f.Write(len, 0); rayA.Beam(f); var fo = Interlocked.Increment(ref totalFragsOut); var ts = Interlocked.Add(ref totalSend, len); string.Format("S: {0, -10} TS: {1, -10} FO: {2, -3}", len, ts, fo).AsInnerInfo(); if (ts > CAP) { break; } } $"Out of beaming loop".AsInnerInfo(); }); ta.Start(); } if (targ.B) { if (!rayB.LockOn(bep, aep)) { $"Failed to lock on rayA".AsError(); } } if (!rst.WaitOne(new TimeSpan(0, 2, 0))) { Passed = false; FailureMessage = "Timeout."; } } await Task.Yield(); if (!Passed.HasValue) { Passed = true; } IsComplete = true; } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { if (rayA != null) { rayA.Dispose(); } if (rayB != null) { rayB.Dispose(); } } }
public async Task Start(IDictionary <string, List <string> > args) { #if !DEBUG && !ASSERT return; #endif Beamer rayA = null; Beamer rayB = null; const int MEG = 1_000_000; try { var targ = new TestArgs(args); var rst = new ManualResetEvent(false); var aep = targ.AE; var bep = targ.BE; rayA = new Beamer( (f) => { }, new BeamerCfg() { Log = new BeamerLogCfg("rayA-DroppingFrames", targ.Log), #if DEBUG || ASSERT dropFrames = true, deopFramePercent = 30 #endif }); rayB = new Beamer((f) => { try { var s = f.Span(); if (s.Length == MEG) { for (int i = 0; i < MEG; i++) { if (f[i] != 43) { Passed = false; "rayB received incorrect data.".AsError(); break; } } Passed = true; "OK: Send/Receive 1meg with dropped random frames on both sides.".AsSuccess(); } else { Passed = false; "rayB receive failed.".AsError(); } } finally { rst.Set(); } }, new BeamerCfg() { Log = new BeamerLogCfg("rayB-DroppingFrames", targ.Log), #if DEBUG || ASSERT dropFrames = true, deopFramePercent = 30 #endif }); using (var hw = new HeapHighway()) { if (rayB.LockOn(bep, aep) && rayA.LockOn(aep, bep) && await rayA.TargetIsActive()) { var f = hw.Alloc(MEG); for (int i = 0; i < MEG; i++) { f[i] = 43; } await rayA.Beam(f); rst.WaitOne(); } } await Task.Yield(); Passed = true; IsComplete = true; } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { rayA.Dispose(); rayB.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { Beamer rayA = null; Beamer rayB = null; try { var rst = new ManualResetEvent(false); var targ = new TestArgs(args); var aep = targ.AE; var bep = targ.BE; rayA = new Beamer((f) => { Console.WriteLine("?"); }, new BeamerCfg() { Log = new BeamerLogCfg("rayA-OneByte", targ.Log) }); rayB = new Beamer((f) => { if (f.Span()[0] == 77) { Passed = true; "OK: rayB received 1 byte.".AsSuccess(); } else { Passed = false; "rayB receive failed.".AsError(); } rst.Set(); }, new BeamerCfg() { Log = new BeamerLogCfg("rayB-OneByte", targ.Log) }); using (var hw = new HeapHighway(50)) { var ta = new Task(async() => { rayA.LockOn(aep, bep); var f = hw.Alloc(1); f.Write((byte)77, 0); await rayA.Beam(f); }); var tb = new Task(async() => { rayB.LockOn(bep, aep); }); ta.Start(); tb.Start(); rst.WaitOne(); } await Task.Yield(); Passed = true; IsComplete = true; } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { rayA.Dispose(); rayB.Dispose(); } }
async Task halfGigNoLogNoVerify(TestArgs targ) { "[In] halfGigNoLogNoVerify()".AsTestInfo(); var started = DateTime.Now; Beamer rayA = null; Beamer rayB = null; const int CAP = 500_000_000; int totalSend = 0; int totalReceived = 0; int totalFragsOut = 0; int totalFragsIn = 0; var rdmSize = new Random(); try { var rst = new ManualResetEvent(false); var aep = targ.AE; var bep = targ.BE; void receive(MemoryFragment f) { int len = 0; bool err = false; int rec = 0; try { var s = f.Span(); f.Read(ref len, 0); var fi = Interlocked.Increment(ref totalFragsIn); if (s.Length == len) { rec = Interlocked.Add(ref totalReceived, len); } else { err = true; } } catch (Exception ex) { ex.ToString().AsError(); } finally { f.Dispose(); var rem = CAP - rec; if (rem < 0) { rem = 0; } $"Rem: {rem} ".AsInnerInfo(); if (err) { "rayB receive failed.".AsError(); rst.Set(); } else if (rec >= CAP) { Passed = true; IsComplete = true; var ts = DateTime.Now.Subtract(started); $"OK: halfGigNoLogNoVerify() {ts.Seconds}s {ts.Milliseconds}ms".AsSuccess(); rst.Set(); } } } var traceops = (LogFlags.ReqTiles | LogFlags.Tile | LogFlags.ProcTile); rayA = new Beamer((f) => { }, new BeamerCfg() { TileSizeBytes = 60000 }); rayB = new Beamer(receive, new BeamerCfg() { Log = new BeamerLogCfg("rayB-HalfGig", targ.Log, traceops), TileSizeBytes = 60000 }); using (var hw = new HeapHighway()) { var ta = new Task(async() => { rayA.LockOn(aep, bep); while (!rayA.IsStopped) { var len = rdmSize.Next(10, 10_000_000); var f = hw.Alloc(len); f.Write(len, 0); rayA.Beam(f).Wait(); Interlocked.Increment(ref totalFragsOut); if (Interlocked.Add(ref totalSend, len) > CAP) { break; } } $"Out of beaming loop".AsInnerInfo(); }); var tb = new Task(async() => { rayB.LockOn(bep, aep); }); ta.Start(); tb.Start(); if (!rst.WaitOne(new TimeSpan(0, 2, 0))) { Passed = false; FailureMessage = "Timeout."; FailureMessage.AsError(); } } await Task.Yield(); if (Passed.HasValue && !Passed.Value || !IsComplete) { "halfGigNoLogNoVerify() failed".AsError(); } } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { rayA.Dispose(); rayB.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { Beamer rayA = null; Beamer rayB = null; const int MEG = 1_000_000; try { var rst = new ManualResetEvent(false); var targ = new TestArgs(args); var aep = targ.AE; var bep = targ.BE; rayA = new Beamer( (f) => { Console.WriteLine("?"); }, new BeamerCfg() { Log = new BeamerLogCfg("rayA-OneMeg", targ.Log) }); rayB = new Beamer((f) => { try { var s = f.Span(); if (s.Length == MEG) { for (int i = 0; i < MEG; i++) { if (f[i] != 43) { Passed = false; "rayB received incorrect data.".AsError(); break; } } Passed = true; "OK: Send/Receive 1meg.".AsSuccess(); } else { Passed = false; "rayB receive failed.".AsError(); } } finally { rst.Set(); } }, new BeamerCfg() { Log = new BeamerLogCfg("rayB-OneMeg", targ.Log) }); using (var hw = new HeapHighway()) { var ta = new Task(async() => { rayA.LockOn(aep, bep); var f = hw.Alloc(MEG); for (int i = 0; i < MEG; i++) { f[i] = 43; } await rayA.Beam(f); }); var tb = new Task(async() => { rayB.LockOn(bep, aep); }); ta.Start(); tb.Start(); rst.WaitOne(); } await Task.Yield(); Passed = true; IsComplete = true; } catch (Exception ex) { FailureMessage = ex.Message; Passed = false; } finally { rayA.Dispose(); rayB.Dispose(); } }
public async Task Start(IDictionary <string, List <string> > args) { Beamer a = null; Beamer b = null; try { var targ = new TestArgs(args); var s = targ.AE; var t = targ.BE; a = new Beamer((_) => { }, new BeamerCfg() { EnableProbes = true, ProbeFreqMS = 400 }); b = new Beamer((_) => { }, new BeamerCfg() { EnableProbes = true, ProbeFreqMS = 100 }); a.LockOn(s, t); b.LockOn(t, s); await Task.Delay(2000); var ap = DateTime.Now.Subtract(b.LastProbe).TotalMilliseconds; var bp = DateTime.Now.Subtract(a.LastProbe).TotalMilliseconds; if (ap > 500) { FailureMessage = $"Expected at least one probe in the {a.Config.ProbeFreqMS} interval"; Passed = false; return; } if (bp > 150) { FailureMessage = $"Expected at least one probe in the {b.Config.ProbeFreqMS} interval"; Passed = false; return; } "OK: Probing loop.".AsSuccess(); // Stop the probing Volatile.Write(ref a.Config.EnableProbes, false); Volatile.Write(ref b.Config.EnableProbes, false); await Task.Delay(2000); ap = DateTime.Now.Subtract(b.LastProbe).TotalMilliseconds; bp = DateTime.Now.Subtract(a.LastProbe).TotalMilliseconds; if (ap < 1000 || bp < 1000) { FailureMessage = $"The probing should have stopped"; Passed = false; return; } "OK: Stopping the probing loop.".AsSuccess(); var apr = a.Probe(); if (!apr) { FailureMessage = $"Probe request failed"; Passed = false; return; } "OK: Probe request.".AsSuccess(); b.Dispose(); apr = a.Probe(300); if (apr) { FailureMessage = $"A probe request succeeded after the remote Beamer was disposed."; Passed = false; return; } Task.Delay(1500).ContinueWith((_) => { b = new Beamer((f) => { }, new BeamerCfg()); b.LockOn(t, s); }); Task.Run(() => { if (!a.TargetIsActive(8000).Result) { Passed = false; FailureMessage = "Second TargetIsActive() await failed"; } else { "OK: Second TargetIsActive() await.".AsSuccess(); } }); apr = await a.TargetIsActive(8000); if (!apr) { FailureMessage = "Awaiting for target to become active with a probe failed!"; Passed = false; return; } "OK: Awaiting for target to become active with a probe.".AsSuccess(); await Task.Delay(300); Passed = true; IsComplete = true; } catch (Exception ex) { Passed = false; FailureMessage = ex.Message; } finally { a.Dispose(); b.Dispose(); } }