public void LoginWithWrongPassword() { proto?.Dispose(); proto = new AlienReaderProtocol(); Assert.Throws <AggregateException>(() => proto.ConnectAndLogin(sim.Host, sim.Port, "alien", "password1").Wait()) .InnerException.ShouldBeOfType <LoginFailedException>(); }
public HardwareTests() { sim = new SimulatorListener(); proto = new AlienReaderProtocol(baseTimeout, baseTimeout * 2); proto.ConnectAndLogin(sim.Host, sim.Port, "alien", "password").Wait(baseTimeout * 2).ShouldBeTrue(); reader = proto.Api; }
public async Task Recover_from_tags_subscriber_error() { Proto.Dispose(); tagStream = new Subject <Tag>(); var p = new AlienReaderProtocol(receiveTimeout: int.MaxValue); p.ConnectAndLogin(Host, Port, "alien", "password").Wait(2000).Should().BeTrue(); p.StartTagPolling(tagStream, errorStream, heartbeatStream).Wait(2000).Should().BeTrue(); var doThrow = false; var badSubscriber = tagStream.Subscribe(x => { if (doThrow) { throw new Exception(); } }); tagStream.Subscribe(tags.Add, ex => throw ex, () => completed = true); await p.Api.AntennaSequence("0"); await new Timing().ExpectAsync(() => tags.Count > 100); errors.Count.Should().Be(0); doThrow = true; await new Timing().ExpectAsync(() => errors.Count > 0); errors[0].Should().BeOfType <Exception>(); tags.Clear(); (await new Timing().Timeout(2000).WaitAsync(() => tags.Count > 0)).Should().BeFalse(); badSubscriber.Dispose(); await new Timing().ExpectAsync(() => tags.Count > 100); }
void WaitForPhysicalReaderToComeback() { if (sim.UsePhysicalDevice) { Logger.Debug("will wait for physical reader to restart"); var i = 0; while (i < 200) { var sw = Stopwatch.StartNew(); try { Logger.Debug("Try {i}", i++); var p = new AlienReaderProtocol(); p.ConnectAndLogin(sim.Host, sim.Port, "alien", "password", 1000).Wait(); sw.Stop(); Logger.Debug("[{Elapsed}]Successfully connected to physical reader", sw.Elapsed); return; } catch (Exception ex) { sw.Stop(); Logger.Debug("[{Elapsed}]Failed to connect to physical reader: {Message}", sw.Elapsed, ex.Message); if (sw.ElapsedMilliseconds < 1000) { Thread.Sleep(1000); } } } throw new Exception("Could not connect to reader after 200 retries"); } }
public AlienReaderFactsWithLogin() { logger = LoggerIndexer.GetCurrentClassLogger(); sim = new SimulatorListener(); proto = new AlienReaderProtocol(baseTimeout, baseTimeout * 2); proto.ConnectAndLogin(sim.Host, sim.Port, "alien", "password").Wait(baseTimeout * 2).ShouldBeTrue(); reader = proto.Api; }
public TagStreamListenerTests() { sim = new SimulatorListener(); proto = new AlienReaderProtocol(receiveTimeout: int.MaxValue); proto.ConnectAndLogin(sim.Host, sim.Port, "alien", "password").Wait(2000).ShouldBeTrue(); proto.StartTagPolling(tagStream).Wait(2000).ShouldBeTrue(); reader = proto.Api; tagStream.Subscribe(tags.Add, ex => throw ex, () => completed = true); proto.TagPoller.UnparsedMessages.Subscribe(msgs.Add); }
public async Task Help_should_work() { if (!Settings.UseHardwareReader) { return; } var proto = new AlienReaderProtocol(); await proto.ConnectAndLogin(Host, Port, "alien", "password"); var info = await proto.Api.Command("help"); info.Should().StartWith("**************************************************************"); info.Length.Should().BeGreaterThan(500); }
public async Task Help_should_work() { if (!sim.UsePhysicalDevice) { return; } var proto = new AlienReaderProtocol(); await proto.ConnectAndLogin(sim.Host, sim.Port, "alien", "password"); var info = await proto.Api.Command("help"); info.ShouldStartWith("**************************************************************"); info.Length.ShouldBeGreaterThan(500); }
public void Reader_bounce_current_client_when_new_comes() { Timing.StartWait(() => (DateTime.Now - proto.LastKeepalive).TotalMilliseconds < AlienReaderProtocol.DefaultKeepaliveTimeout, AlienReaderProtocol.DefaultReceiveTimeout) .Result .ShouldBeTrue("Did not get first keepalive"); using (var r2 = new AlienReaderProtocol()) { Logger.Debug("Connecting second client"); r2.ConnectAndLogin(sim.Host, sim.Port, "alien", "password").Wait(6000).ShouldBeTrue(); Logger.Debug("Second client connected"); } Logger.Debug("Second client disconnected"); Timing.StartWait(() => (DateTime.Now - proto.LastKeepalive).TotalMilliseconds > AlienReaderProtocol.DefaultKeepaliveTimeout * 2, AlienReaderProtocol.DefaultReceiveTimeout * 2) .Result .ShouldBeTrue($"Still getting keepalives {proto.LastKeepalive} {DateTime.Now}"); Logger.Information("Keepalives stopped"); Timing.StartWait(() => !proto.IsConnected).Result.ShouldBe(true); }
public void Reader_bounce_current_client_when_new_comes() { new Timing() .Timeout(AlienReaderProtocol.DefaultReceiveTimeout) .Context("Did not get first keepalive") .Expect(() => (DateTime.UtcNow - Proto.LastKeepalive).TotalMilliseconds < AlienReaderProtocol.DefaultKeepaliveTimeout); using (var r2 = new AlienReaderProtocol()) { Logger.Debug("Connecting second client"); r2.ConnectAndLogin(Host, Port, "alien", "password").Wait(6000).Should().BeTrue(); Logger.Debug("Second client connected"); } Logger.Debug("Second client disconnected"); new Timing() .Timeout(AlienReaderProtocol.DefaultReceiveTimeout * 2) .FailureDetails(() => $"Still getting keepalives {Proto.LastKeepalive} {DateTime.UtcNow}") .Expect(() => (DateTime.UtcNow - Proto.LastKeepalive).TotalMilliseconds > AlienReaderProtocol.DefaultKeepaliveTimeout * 2); Logger.Information("Keepalives stopped"); new Timing().Expect(() => !Proto.IsConnected); }
public ReaderFixture() { Settings = new ConfigurationBuilder() .AddJsonFile("alien-test-settings.json", true) .AddEnvironmentVariables() .Build() .Get <AlienTestSettings>(); if (Settings.UseHardwareReader) { UseEndpoint(Settings.HardwareReaderAddress); } else { Simulator = new SimulatorListener(UseEndpoint(Settings.ReaderSimAddress)); Port = Simulator.ListenEndpoint.Port; } Proto = new AlienReaderProtocol(); Proto.ConnectAndLogin(Host, Port, "alien", "password") .Wait(AlienReaderProtocol.DefaultConnectTimeout).Should().BeTrue(); }
public AlienReaderProtocolTests() { sim = new SimulatorListener(); proto = new AlienReaderProtocol(); proto.ConnectAndLogin(sim.Host, sim.Port, "alien", "password").Wait(2000).ShouldBeTrue(); }