public async Task ServiceBusWaitAndCheckTrueTest() { const int TIMEOUT = 10000; const int SHOULDBELESSTHAN = 2000; var topic = Guid.NewGuid().ToString(); var subscription = Guid.NewGuid().ToString(); var filter = "foobar"; await EnsureTopicExists(_d.Settings.ServiceBusAccount, topic); Ended endedHow = Ended.Unknown; try { var sw = new Stopwatch(); sw.Start(); await using (var waitAndCheck = new ServiceBusWaitAndCheck(_d.Settings.ServiceBusAccount, topic, subscription, filter, () => { return(Task.FromResult(true)); }, TIMEOUT)) { await waitAndCheck.WaitAsync(); endedHow = waitAndCheck.EndedHow; } sw.Stop(); Assert.IsTrue(sw.ElapsedMilliseconds <= SHOULDBELESSTHAN); } finally { await DeleteTopic(_d.Settings.ServiceBusAccount, topic); } }
public async Task ServiceBusWaitAndCheckTwentySecondUploadTest() { const int TIMEOUT = 20000; const int WAITTIME = 20000; const int ACCEPTABLELATENCY = 2000; var topic = Guid.NewGuid().ToString(); var subscription = Guid.NewGuid().ToString(); var messageToSend = new TestMessage { Message = $"{subscription}" }; var filter = "foobar"; var imageUploaded = new ImageUploaded(); await EnsureTopicExists(_d.Settings.ServiceBusAccount, topic); Ended endedHow = Ended.Unknown; try { var sw = new Stopwatch(); sw.Start(); _ = Task.Run(() => { try { Task.Delay(WAITTIME).Wait(); imageUploaded.Uploaded(); SendMessageAsync(_d.Settings.ServiceBusAccount, topic, messageToSend, subscriptionFilter: filter).Wait(); } catch { } }); await using (var waitAndCheck = new ServiceBusWaitAndCheck(_d.Settings.ServiceBusAccount, topic, subscription, filter, () => { return(Task.FromResult(imageUploaded.IsUploaded)); }, TIMEOUT)) { await waitAndCheck.WaitAsync(); endedHow = waitAndCheck.EndedHow; } sw.Stop(); Assert.IsTrue(sw.ElapsedMilliseconds > WAITTIME, "Did not wait long enough."); Assert.IsTrue(sw.ElapsedMilliseconds > TIMEOUT, "Released before timeout."); Assert.IsTrue(sw.ElapsedMilliseconds < (WAITTIME + ACCEPTABLELATENCY), "Did not receive message in time."); Assert.IsTrue(endedHow == Ended.Timeout || endedHow == Ended.Success); } finally { await DeleteTopic(_d.Settings.ServiceBusAccount, topic); } }
public async Task WaitForImage([FromBody] WaitForImage waitForImage) { CheckIsNotNull(nameof(waitForImage), waitForImage); Func <Task <bool> > check = async() => { return(await FileOrFolderExists(_d.Settings.StorageAccount, "images", waitForImage.Image)); }; try { await using (var sb = new ServiceBusWaitAndCheck(_d.Settings.ServiceBusAccount, "notifications", Guid.NewGuid().ToString(), waitForImage.Image, check)) { _d.Logger.LogDebug("Entering wait for image."); await sb.WaitAsync(); } } catch (Exception ex) { _d.Logger.LogError(ex.Message); // DO NOT RETHROW } }
public async Task ServiceBusWaitAndCheckFalseTimeoutTest() { const int TIMEOUT = 10000; const int ACCEPTABLELATENCY = 2000; var topic = Guid.NewGuid().ToString(); var subscription = Guid.NewGuid().ToString(); var filter = "foobar"; await EnsureTopicExists(_d.Settings.ServiceBusAccount, topic); Ended endedHow = Ended.Unknown; try { var sw = new Stopwatch(); sw.Start(); await using (var waitAndCheck = new ServiceBusWaitAndCheck(_d.Settings.ServiceBusAccount, topic, subscription, filter, () => { return(Task.FromResult(false)); }, TIMEOUT)) { await waitAndCheck.WaitAsync(); endedHow = waitAndCheck.EndedHow; } sw.Stop(); Assert.IsTrue(sw.ElapsedMilliseconds >= TIMEOUT, "Did not wait for the timeout."); Assert.IsTrue(sw.ElapsedMilliseconds < (TIMEOUT + ACCEPTABLELATENCY), "Took to long to return."); Assert.IsTrue(endedHow == Ended.Timeout || endedHow == Ended.Success); } finally { await DeleteTopic(_d.Settings.ServiceBusAccount, topic); } }