public async Task edge_case_cancel_after_delay_before_retry() { var waiter = new ManualResetEventSlim(false); var backoffAwaiter = new AutoResetAwaitable(); var backoffCalculated = false; var listener = Structure.Start( new SimpleProperties(), TestOptions( next => env => env.Response(500), op => { var existingBackoff = op.HttpBackoff; op.HttpBackoff = (options, existing) => { backoffAwaiter.Signal(); waiter.Wait(); backoffCalculated = true; return(existingBackoff(options, existing)); }; })); ConsulKvSimulator.PutKey("test", "1"); await backoffAwaiter.WaitOne(); // first request stopping var stopper = listener.Stop(); //stopper.Start(); waiter.Set(); await stopper; backoffCalculated.ShouldBeTrue(); }
public async Task receives_key() { string receivedKey = null; byte[] receivedValue = null; Action <IEnumerable <KeyValuePair <string, byte[]> > > keyReceiver = (kvs) => { foreach (var kv in kvs) { receivedKey = kv.Key; receivedValue = kv.Value; } }; var updater = Structure.Start(keyReceiver, TestOptions()); ConsulKvSimulator.PutKey("key", "value"); var assignedKv = await KeyValuesAssigned.Dequeue(); receivedKey.ShouldBe(assignedKv.Single().Key); receivedKey.ShouldBe("key"); receivedValue.ShouldBe(Encoding.UTF8.GetBytes("value")); receivedValue.ShouldBe(assignedKv.Single().Value); await updater.Stop(); }
public async Task key_is_assigned_once() { var config = new SimpleProperties(); var updater = Structure.Start(config, TestOptions()); ConsulKvSimulator.PutKey("keystring", "http"); await KeyValuesAssigned.Dequeue(); config.KeyString.ShouldBe("http"); await updater.Stop(); }
public async Task retries_on_errors_until_successful() { int retries = 0; var listener = Structure.Start( new SimpleProperties(), TestOptions(next => env => (retries++ < 1 ? env.Response(500) : next(env)))); ConsulKvSimulator.PutKey("keystring", "first"); var success = await HttpSuccesses.Dequeue(); success.Item2.StatusCode.ShouldBe((HttpStatusCode)200); await listener.Stop(); }
public async Task http_events_published() { var config = new SimpleProperties(); var updater = Structure.Start(config, TestOptions()); ConsulKvSimulator.PutKey("keystring", "http"); var result = await HttpSuccesses.Dequeue(); result.Item1.RequestUri.AbsolutePath.ShouldStartWith("/v1/kv/"); result.Item2.StatusCode.ShouldBe(HttpStatusCode.OK); result.Item3.ShouldBeGreaterThan(TimeSpan.Zero); await updater.Stop(); }
public async Task mutliple_key_changes_get_correct_value() { var config = new SimpleProperties(); ConsulKvSimulator.PutKey("keystring", "first"); ConsulKvSimulator.PutKey("keystring", "second"); var updater = Structure.Start(config, TestOptions()); var lastResult = await KeyValuesAssigned.Dequeue(); lastResult.Last().Value.ShouldBe("second"); config.KeyString.ShouldBe("second"); await updater.Stop(); }
public async Task key_is_assigned_repeatedly() { var config = new SimpleProperties(); var updater = Structure.Start(config, TestOptions()); ConsulKvSimulator.PutKey("keystring", "first"); await KeyValuesAssigned.Dequeue(); config.KeyString.ShouldBe("first"); await Task.WhenAll( ConsulKvSimulator.PutKeyWithDelay("keystring", "second", TimeSpan.FromSeconds(3)), KeyValuesAssigned.Dequeue()); config.KeyString.ShouldBe("second"); await updater.Stop(); }
public async Task nanIndexHeader() { var listener = Structure.Start( new SimpleProperties(), TestOptions( next => env => { env.Response.Headers["X-Consul-Index"] = "nope"; return(env.Response(200)); })); ConsulKvSimulator.PutKey("kv", "nope"); var exception = await HttpErrors.Dequeue(); exception.ShouldBeOfType <InvalidOperationException>(); await listener.Stop(); }
public async Task tooManyIndexHeader() { var listener = Structure.Start( new SimpleProperties(), TestOptions( next => env => { env.Response.Headers.Add("X-Consul-Index", new[] { "1", "2" }); return(env.Response(200)); })); ConsulKvSimulator.PutKey("kv", "nope"); var exception = await HttpErrors.Dequeue(); Trace.WriteLine(exception.Message); exception.ShouldBeOfType <InvalidOperationException>(); await listener.Stop(); }