Skip to content

Commit

Permalink
Use async delay
Browse files Browse the repository at this point in the history
  • Loading branch information
inputfalken committed Jul 15, 2024
1 parent b4dced2 commit 4e12b2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/Dynatello/Handlers/TableAccessExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using DynamoDBGenerator;
using Dynatello.Builders;
Expand Down
16 changes: 11 additions & 5 deletions tests/Dynatello.Tests/HandlerTests/GetRequestHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ private class TestPipeLine : IRequestPipeLine
{
public DateTime? TimeStamp = null;

public Task<AmazonWebServiceResponse> Invoke(
public async Task<AmazonWebServiceResponse> Invoke(
RequestContext requestContext,
Func<RequestContext, Task<AmazonWebServiceResponse>> continuation
)
{
await Task.Delay(50);
TimeStamp = DateTime.Now;
return continuation(requestContext);
return await continuation(requestContext);
}
}

Expand All @@ -39,14 +40,16 @@ public async Task Send_SuccessMockWithMockedRequestPipeline_ShouldReturnItemAndE

amazonDynamoDB
.GetItemAsync(Arg.Any<GetItemRequest>())
.Returns(x =>
.Returns(async x =>
{
Thread.Sleep(200);
await Task.Delay(200);
return response;
});

var pipelines = new TestPipeLine[]
{
new TestPipeLine(),
new TestPipeLine(),
new TestPipeLine(),
new TestPipeLine(),
new TestPipeLine()
Expand All @@ -62,18 +65,21 @@ public async Task Send_SuccessMockWithMockedRequestPipeline_ShouldReturnItemAndE
x.RequestsPipelines.Add(pipelines[0]);
x.RequestsPipelines.Add(pipelines[1]);
x.RequestsPipelines.Add(pipelines[2]);
x.RequestsPipelines.Add(pipelines[3]);
x.RequestsPipelines.Add(pipelines[4]);
x.AmazonDynamoDB = amazonDynamoDB;
}
)
.Send(expected.Id, default);
Assert.Equal(expected, actual);
Assert.All(pipelines, x => Assert.NotNull(x.TimeStamp));
var pipeLineTimestamps = pipelines.Select(x => x.TimeStamp!.Value).ToArray();

Assert.DoesNotContain(
false,
pipeLineTimestamps.Zip(
pipeLineTimestamps.Skip(1),
(x, y) => (x < y) && (y - x) < TimeSpan.FromMilliseconds(20) // ugly hack to verify that request comes last.
(x, y) => (x < y) && (y - x) < TimeSpan.FromMilliseconds(100) // ugly hack to verify that request comes last.
)
);
}
Expand Down

0 comments on commit 4e12b2e

Please sign in to comment.