@@ -693,7 +693,7 @@ await db.Execute(
693693 Assert . Equal ( 5 , callCount ) ;
694694 }
695695
696- [ Fact ]
696+ [ Fact ( Timeout = 2000 ) ]
697697 public async Task WatchSchemaResetTest ( )
698698 {
699699 var initialSchema = new Schema (
@@ -711,7 +711,7 @@ public async Task WatchSchemaResetTest()
711711 new Table
712712 {
713713 Name = "assets_synced" ,
714- ViewName = "assets_inactive " ,
714+ ViewName = "assets_synced_inactive " ,
715715 Columns =
716716 {
717717 [ "make" ] = ColumnType . Text ,
@@ -724,11 +724,10 @@ public async Task WatchSchemaResetTest()
724724 new Table
725725 {
726726 Name = "assets_local" ,
727- ViewName = "assets_inactive " ,
727+ ViewName = "assets_local_inactive " ,
728728 Columns =
729729 {
730730 [ "make" ] = ColumnType . Text ,
731- [ "model" ] = ColumnType . Text ,
732731 [ "description" ] = ColumnType . Text ,
733732 }
734733 } ,
@@ -739,7 +738,6 @@ public async Task WatchSchemaResetTest()
739738 Columns =
740739 {
741740 [ "make" ] = ColumnType . Text ,
742- [ "model" ] = ColumnType . Text ,
743741 [ "description" ] = ColumnType . Text ,
744742 }
745743 }
@@ -755,20 +753,44 @@ public async Task WatchSchemaResetTest()
755753 Schema = initialSchema
756754 } ) ;
757755
758- // TODO: Setup query watching 'assets'
759- // Setup semaphore to track successful watches
756+ var sem = new SemaphoreSlim ( 0 ) ;
757+ var callCount = 0 ;
758+
759+ var query = await db . Watch ( "SELECT * FROM assets" , [ ] , new WatchHandler < AssetResult >
760+ {
761+ OnResult = ( result ) =>
762+ {
763+ Interlocked . Increment ( ref callCount ) ;
764+ sem . Release ( ) ;
765+ } ,
766+ OnError = error => throw error
767+ } ) ;
768+ Assert . True ( await sem . WaitAsync ( 100 ) ) ;
769+ Assert . Equal ( 1 , callCount ) ;
770+
771+ for ( int i = 0 ; i < 3 ; i ++ )
772+ {
773+ await db . Execute (
774+ "insert into assets(id, description, make) values (?, ?, ?)" ,
775+ [ Guid . NewGuid ( ) . ToString ( ) , "some desc" , "some make" ]
776+ ) ;
777+ Assert . True ( await sem . WaitAsync ( 100 ) ) ;
778+ }
779+ Assert . Equal ( 4 , callCount ) ;
760780
761- // TODO: INSERT into 'assets'
762- // Verify correct count (3)
781+ await db . UpdateSchema ( updatedSchema ) ;
782+ Assert . True ( await sem . WaitAsync ( 100 ) ) ;
783+ Assert . Equal ( 5 , callCount ) ;
763784
764- // TODO: Update schema to change underlying table name without changing view name
785+ await db . Execute ( "insert into assets select * from assets_local_inactive" ) ;
786+ Assert . True ( await sem . WaitAsync ( 100 ) ) ;
787+ Assert . Equal ( 6 , callCount ) ;
765788
766- // TODO: INSERT all data from "assets_local" into "assets_synced"
767- // Verify correct count (6)
789+ query . Dispose ( ) ;
790+ await Task . Delay ( 200 ) ;
768791
769- // ** Sanity check **
770- // TODO: Deregister query
771- // Change schema back to initial and update data
772- // Verify correct count (6) (unchanged)
792+ await db . Execute ( "update assets set description = 'another desc'" ) ;
793+ Assert . False ( await sem . WaitAsync ( 100 ) ) ;
794+ Assert . Equal ( 6 , callCount ) ;
773795 }
774796}
0 commit comments