Skip to content

Commit 45bb4b6

Browse files
committed
Add test for ExecuteBatch
1 parent f3dc694 commit 45bb4b6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Tests/PowerSync/PowerSync.Common.Tests/Client/PowerSyncDatabaseTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,4 +1035,36 @@ public async Task OnChange_ThrottleCancelledCleanly()
10351035

10361036
Assert.True(await tcs.Task);
10371037
}
1038+
1039+
[Fact]
1040+
public async Task Watch_SingleEventForBatchedQuery()
1041+
{
1042+
int eventCount = 0;
1043+
long lastCount = 0;
1044+
var tcs = new TaskCompletionSource<bool>();
1045+
1046+
var listener = db.Watch<CountResult>(
1047+
"select count(*) as count from assets",
1048+
null,
1049+
new() { Signal = testCts.Token });
1050+
1051+
_ = Task.Run(async () =>
1052+
{
1053+
await foreach (var rows in listener)
1054+
{
1055+
lastCount = rows[0].count;
1056+
Interlocked.Increment(ref eventCount);
1057+
}
1058+
tcs.TrySetResult(true);
1059+
});
1060+
1061+
// Long batched query
1062+
const int QUERY_COUNT = 10000;
1063+
await TestUtils.InsertRandomAssets(db, QUERY_COUNT);
1064+
1065+
testCts.Cancel();
1066+
Assert.True(await tcs.Task);
1067+
Assert.Equal(1, eventCount);
1068+
Assert.Equal(QUERY_COUNT, lastCount);
1069+
}
10381070
}

0 commit comments

Comments
 (0)