Skip to content

Commit 58fa056

Browse files
committed
Add failing test.
1 parent 90cff10 commit 58fa056

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/powersync/test/streaming_sync_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,43 @@ void main() {
102102
}
103103
await pdb.close();
104104
});
105+
106+
test('multiple connect calls', () async {
107+
// Test repeatedly creating new PowerSync connections, then disconnect
108+
// and close the connection.
109+
final random = Random();
110+
var server = await createServer();
111+
112+
credentialsCallback() async {
113+
return PowerSyncCredentials(endpoint: server.endpoint, token: 'token');
114+
}
115+
116+
final pdb = await setupPowerSync(path: path);
117+
pdb.retryDelay = Duration(milliseconds: 5000);
118+
var connector = TestConnector(credentialsCallback);
119+
pdb.connect(connector: connector);
120+
pdb.connect(connector: connector);
121+
122+
final watch = Stopwatch()..start();
123+
124+
// Wait for at least one connection
125+
while (server.connectionCount < 1 && watch.elapsedMilliseconds < 500) {
126+
await Future.delayed(Duration(milliseconds: random.nextInt(10)));
127+
}
128+
// Give some time for a second connection if any
129+
await Future.delayed(Duration(milliseconds: random.nextInt(50)));
130+
131+
await pdb.close();
132+
133+
// Give some time for connections to close
134+
while (server.connectionCount != 0 && watch.elapsedMilliseconds < 1000) {
135+
await Future.delayed(Duration(milliseconds: random.nextInt(10)));
136+
}
137+
138+
expect(server.connectionCount, equals(0));
139+
expect(server.maxConnectionCount, equals(1));
140+
141+
server.close();
142+
});
105143
});
106144
}

0 commit comments

Comments
 (0)