@@ -42,22 +42,26 @@ public void WillSaveOnce() {
4242
4343 [ Fact ]
4444 public void WillOverwriteSetting ( ) {
45- var latch = new CountDownLatch ( 2 ) ;
45+ using var saved = new AutoResetEvent ( false ) ;
4646 var storage = new InMemoryObjectStorage ( ) ;
4747 var dict = new PersistedDictionary ( "test.json" , storage , new DefaultJsonSerializer ( ) , 50 ) ;
48- dict . Saved += ( sender , args ) => latch . Signal ( ) ;
48+ int saveCount = 0 ;
49+ dict . Saved += ( sender , args ) => {
50+ Interlocked . Increment ( ref saveCount ) ;
51+ saved . Set ( ) ;
52+ } ;
4953
5054 dict [ "MySetting" ] = "ABCDE" ;
5155 Assert . Single ( dict ) ;
52- bool success = latch . Wait ( 500 ) ;
53- Assert . False ( success , "Dictionary was saved multiple times." ) ;
54- Assert . Equal ( 1 , latch . Remaining ) ;
56+ Assert . True ( saved . WaitOne ( 5000 ) , "Failed to save the initial setting." ) ;
57+ Assert . False ( saved . WaitOne ( 250 ) , "Dictionary was saved multiple times." ) ;
58+ Assert . Equal ( 1 , saveCount ) ;
5559 Assert . True ( storage . Exists ( "test.json" ) ) ;
5660
5761 dict [ "MySetting" ] = "AB" ;
5862 Assert . Single ( dict ) ;
59- success = latch . Wait ( 500 ) ;
60- Assert . True ( success , "Failed to save dictionary." ) ;
63+ Assert . True ( saved . WaitOne ( 5000 ) , "Failed to save the overwritten setting." ) ;
64+ Assert . Equal ( 2 , saveCount ) ;
6165 Assert . True ( storage . Exists ( "test.json" ) ) ;
6266 }
6367 }
0 commit comments