public void TestDocumentChange() { var exp1 = new WaitAssert(); var exp2 = new WaitAssert(); Db.AddDocumentChangeListener("doc1", (sender, args) => { WriteLine("Reached document changed callback"); exp2.RunAssert(() => { WriteLine("Waiting for exp1 in document changed callback"); exp1.WaitForResult(TimeSpan.FromSeconds(20)); // Test deadlock }); }); WriteLine("Triggering async save"); var ignore = exp1.RunAssertAsync(() => { WriteLine("Running async save"); Db.Save(new MutableDocument("doc1")); WriteLine("Async save completed"); }); WriteLine("Waiting for exp1 in test method"); exp1.WaitForResult(TimeSpan.FromSeconds(10)); }
public async Task TestAddSameChangeListeners() { var doc1 = new MutableDocument("doc1"); doc1.SetString("name", "Scott"); var saved = Db.Save(doc1); doc1.Dispose(); doc1 = saved.ToMutable(); Db.AddDocumentChangeListener("doc1", DocumentChanged); Db.AddDocumentChangeListener("doc1", DocumentChanged); Db.AddDocumentChangeListener("doc1", DocumentChanged); Db.AddDocumentChangeListener("doc1", DocumentChanged); Db.AddDocumentChangeListener("doc1", DocumentChanged); _wa = new WaitAssert(); _expectedDocumentChanges = new HashSet <string> { "doc1" }; doc1.SetString("name", "Scott Tiger"); Db.Save(doc1); await Task.Delay(500); _wa.CaughtExceptions.Should().BeEmpty("because otherwise too many callbacks happened"); }
public void TestDocumentChange() { var doc1 = new MutableDocument("doc1"); doc1.SetString("name", "Scott"); doc1 = Db.Save(doc1).ToMutable(); var doc2 = new MutableDocument("doc2"); doc2.SetString("name", "Daniel"); doc2 = Db.Save(doc2).ToMutable(); Db.AddDocumentChangeListener("doc1", DocumentChanged); Db.AddDocumentChangeListener("doc2", DocumentChanged); Db.AddDocumentChangeListener("doc3", DocumentChanged); _expectedDocumentChanges = new HashSet <string> { "doc1", "doc2", "doc3" }; _wa = new WaitAssert(); doc1.SetString("name", "Scott Tiger"); Db.Save(doc1); Db.Delete(doc2); var doc3 = new MutableDocument("doc3"); doc3.SetString("name", "Jack"); Db.Save(doc3); _wa.WaitForResult(TimeSpan.FromSeconds(5)); }
public async Task TestRemoveDocumentChangeListener() { var doc1 = new MutableDocument("doc1"); doc1.SetString("name", "Scott"); Db.Save(doc1); var token = Db.AddDocumentChangeListener("doc1", DocumentChanged); _wa = new WaitAssert(); _expectedDocumentChanges = new HashSet <string> { "doc1" }; doc1.SetString("name", "Scott Tiger"); Db.Save(doc1); _wa.WaitForResult(TimeSpan.FromSeconds(5)); Db.RemoveChangeListener(token); _wa = new WaitAssert(); _docCallbackShouldThrow = true; doc1.SetString("name", "Scott Pilgrim"); Db.Save(doc1); await Task.Delay(500); _wa.CaughtExceptions.Should().BeEmpty("because otherwise too many callbacks happened"); // Remove again Db.RemoveChangeListener(token); }