Last active
March 7, 2022 16:27
-
-
Save joeyguerra/aa7e6c8ff62749845e3a5d188f5826df to your computer and use it in GitHub Desktop.
Integration test for Redis Pub/Sub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public async void ShouldPublishResultMessage() | |
{ | |
var messageContract = File.ReadAllText("MessageContract.json"); | |
var expected = JsonSerializer.Deserialize<Result>(messageContract); | |
var subscriber = _fixture.RedisPersistence.GetSubscriber(); | |
var tcs = new TaskCompletionSource<Result>(); | |
subscriber.Subscribe("channel:result", (channel, message) => | |
{ | |
var result = JsonSerializer.Deserialize<Result>(message); | |
tcs.SetResult(result); | |
}); | |
await _fixture.RedisPersistence.PublishResult("channel:result", expected); | |
var actual = await Task.WhenAny<Result>(tcs.Task, Task.Run<Result>(async ()=>{ | |
await Task.Delay(3000); | |
return new Result(); | |
})); | |
Assert.Equal(expected, actual); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment