Skip to content

Commit

Permalink
tests: add test to validate watch to grpc new results
Browse files Browse the repository at this point in the history
  • Loading branch information
aneojgurhem committed Sep 27, 2023
1 parent 2d040a5 commit f128cb2
Showing 1 changed file with 106 additions and 1 deletion.
107 changes: 106 additions & 1 deletion Common/tests/WatchToGrpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ await taskList.WhenAll()


[Test]
public async Task UseMongoShouldSucceed()
public async Task UseMongoForTasksShouldSucceed()
{
using var helper = new TestDatabaseProvider(collection => collection.AddSingleton<WatchToGrpc>());

Expand Down Expand Up @@ -174,6 +174,111 @@ await taskTable.CreateTasks(new[]
list.Count);
}

[Test]
public async Task UseMongoForResultsShouldSucceed()
{
using var helper = new TestDatabaseProvider(collection => collection.AddSingleton<WatchToGrpc>());

var resultTable = helper.GetRequiredService<IResultTable>();

await resultTable.Create(new[]
{
new Result("SessionId",
"ResultIsAvailable",
"",
"OwnerId",
ResultStatus.Completed,
new List<string>(),
DateTime.Today,
new[]
{
(byte)1,
}),
new Result("SessionId",
"ResultIsNotAvailable",
"",
"OwnerId",
ResultStatus.Aborted,
new List<string>(),
DateTime.Today,
new[]
{
(byte)1,
}),
new Result("SessionId",
"ResultIsCreated",
"",
"OwnerId",
ResultStatus.Created,
new List<string>(),
DateTime.Today,
new[]
{
(byte)1,
}),
new Result("SessionId",
"ResultIsCreated2",
"",
"OwnerId",
ResultStatus.Created,
new List<string>(),
DateTime.Today,
new[]
{
(byte)1,
}),
new Result("SessionId",
"ResultIsCompletedWithDependents",
"",
"OwnerId",
ResultStatus.Completed,
new List<string>
{
"Dependent1",
"Dependent2",
},
DateTime.Today,
new[]
{
(byte)1,
}),
})
.ConfigureAwait(false);

var wtg = helper.GetRequiredService<WatchToGrpc>();

var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
var list = new List<EventSubscriptionResponse>();

Assert.That(async () =>
{
try
{
// Simple* that are used to create this instance return static events
await foreach (var eventSubscriptionResponse in wtg.GetEvents("SessionId",
new List<EventsEnum>
{
EventsEnum.NewResult,
},
null,
null,
cts.Token)
.ConfigureAwait(false))
{
Console.WriteLine(eventSubscriptionResponse);
list.Add(eventSubscriptionResponse);
}
}
catch (OperationCanceledException)
{
throw new TaskCanceledException();
}
},
Throws.Exception.TypeOf<TaskCanceledException>());

Assert.AreEqual(5,
list.Count);
}

private static readonly TaskOptions Options = new(new Dictionary<string, string>
{
Expand Down

0 comments on commit f128cb2

Please sign in to comment.