Created
June 18, 2020 12:20
-
-
Save Kikimora/5007f9d27fa9c23ccfb553cdabbf7e94 to your computer and use it in GitHub Desktop.
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
//DbQueries - observabe that get all DB queries and can either pass it to Db or produce own result. | |
//Archive - bot orders archive service | |
//Archive.Save - queue order for saving | |
//inserts - delayed (x.Delay()) observable sequence of queries, query won't finish until Continue() is called. | |
[Test] | |
public void FinishDbWrites() | |
{ | |
//arrange - start several update operations right before StopAsync | |
var inserts = DbQueries.Where(x => x.Command.IsInsert(BotOrderEntity.TableName)).Do(x => x.Delay()); | |
var iter = ObservableIterator.For(inserts); | |
Archive.Save("Fake", "Test Account", "Order 1", SampleData.Request).Should().BeTrue(); | |
Archive.Save("Fake", "Test Account", "Order 2", SampleData.Request).Should().BeTrue(); | |
Archive.Save("Fake", "Test Account", "Order 3", SampleData.Request).Should().BeTrue(); | |
//act - call StopAsync while update operations are running | |
var firstInsertQuery = iter.Next().Timeout(); | |
Archive.StopAsync(default); | |
firstInsertQuery.Continue(); | |
iter.Next().Timeout().Continue(); | |
iter.Next().Timeout().Continue(); | |
//assert | |
Wait.For(() => Archive.IsRunning.Should().BeFalse()); | |
Wait.For(() => Db.Orders.AsQueryable().Select(x => x.ExternalId).Should().BeEquivalentTo("Order 1", "Order 2", "Order 3")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment