public async Task PoisonQueueTest() { _host = new HostBuilder() .ConfigureDefaultTestHost <SampleTriggerWithPoisonQueue>(b => { // each test will have a unique hostId so that consecutive test run will not be affected by clean up code b.UseHostId(Guid.NewGuid().ToString("N")) .AddAzureStorageBlobs().AddAzureStorageQueues() .AddExtension <DispatchQueueTestConfig>(); }) .Build(); { _funcInvocation = new ConcurrentStringSet(); _host.Start(); _stopwatch.Restart(); // this test takes long since it does at least 5 dequeue on the poison message // count retries caused by failures and poison queue function process int funcWithExceptionCount = DispatchQueueTestConfig.BatchSize + _host.GetOptions <QueuesOptions>().MaxDequeueCount; await TestHelpers.Await(() => _funcInvocation.TotalAdd() >= funcWithExceptionCount, 10000, 1000); Assert.AreEqual(funcWithExceptionCount, _funcInvocation.TotalAdd()); Assert.True(_funcInvocation.HasDuplicate()); Assert.True(SampleTriggerWithPoisonQueue.PoisonQueueResult); _stopwatch.Stop(); } }
public async void PoisonQueueTest() { _hostConfiguration.TypeLocator = new FakeTypeLocator(typeof(SampleTriggerWithPoisonQueue)); _hostConfiguration.HostId = "pqtest"; using (var host = new JobHost(_hostConfiguration)) { _funcInvokation = new ConcurrentStringSet(); host.Start(); _stopwatch.Restart(); // this test takes long since it does at least 5 dequeue on the poison message // count retries caused by failures and poison queue function process int funcWithExceptionCount = DispatchQueueTestConfig.BatchSize + _hostConfiguration.Queues.MaxDequeueCount; await TestHelpers.Await(() => _funcInvokation.TotalAdd() >= funcWithExceptionCount, 10000, 1000); Assert.Equal(funcWithExceptionCount, _funcInvokation.TotalAdd()); Assert.True(_funcInvokation.HasDuplicate()); Assert.True(SampleTriggerWithPoisonQueue.PoisonQueueResult); _stopwatch.Stop(); } }
// same trigger type, multiple functions public async Task DispatchQueueBatchTriggerTest() { _host = new HostBuilder() .ConfigureDefaultTestHost <SampleTrigger>(b => { // each test will have a unique hostId so that consecutive test run will not be affected by clean up code b.UseHostId(Guid.NewGuid().ToString("N")) .AddAzureStorageBlobs().AddAzureStorageQueues() .AddExtension <DispatchQueueTestConfig>(); }) .Build(); { _funcInvocation = new ConcurrentStringSet(); _host.Start(); _stopwatch.Restart(); int twoFuncCount = DispatchQueueTestConfig.BatchSize * 2; await TestHelpers.Await(() => _funcInvocation.TotalAdd() >= twoFuncCount || _funcInvocation.HasDuplicate(), 7000, 1000); // make sure each function is triggered once and only once Assert.AreEqual(twoFuncCount, _funcInvocation.TotalAdd()); Assert.False(_funcInvocation.HasDuplicate()); _stopwatch.Stop(); } }
// same trigger type, multiple functions public async Task DispatchQueueBatchTriggerTest() { _hostConfiguration.TypeLocator = new FakeTypeLocator(typeof(SampleTrigger)); // each test will have a unique hostId so that consecutive test run will not be affected by clean up code _hostConfiguration.HostId = "bttest"; using (var host = new JobHost(_hostConfiguration)) { _funcInvokation = new ConcurrentStringSet(); host.Start(); _stopwatch.Restart(); int twoFuncCount = DispatchQueueTestConfig.BatchSize * 2; await TestHelpers.Await(() => _funcInvokation.TotalAdd() >= twoFuncCount || _funcInvokation.HasDuplicate(), 7000, 1000); // make sure each function is triggered once and only once Assert.Equal(twoFuncCount, _funcInvokation.TotalAdd()); Assert.False(_funcInvokation.HasDuplicate()); _stopwatch.Stop(); } }