Skip to content

Commit

Permalink
Remove all sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 13, 2023
1 parent 8204197 commit bac416c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions internal/api/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,16 @@ func (c *JSClient) UserID() string {
// Tests should call stopSyncing() at the end of the test.
func (c *JSClient) StartSyncing(t *testing.T) (stopSyncing func()) {
t.Logf("%s is starting to sync", c.userID)
chrome.MustExecute(t, c.ctx, fmt.Sprintf(`window.__client.on("sync", function(state) {
if (state !== "PREPARED") {
return;
}
console.log("%s"+"sync||{\"type\":\"sync\",\"content\":{}}");
});`, CONSOLE_LOG_CONTROL_STRING))
chrome.MustExecute(t, c.ctx, fmt.Sprintf(`
var fn;
fn = function(state) {
if (state !== "SYNCING") {
return;
}
console.log("%s"+"sync||{\"type\":\"sync\",\"content\":{}}");
window.__client.off("sync", fn);
};
window.__client.on("sync", fn);`, CONSOLE_LOG_CONTROL_STRING))
ch := make(chan struct{})
cancel := c.listenForUpdates(func(roomID string, ev Event) {
if roomID != "sync" {
Expand All @@ -189,7 +193,6 @@ func (c *JSClient) StartSyncing(t *testing.T) (stopSyncing func()) {
}
cancel()
t.Logf("%s is now syncing", c.userID)
time.Sleep(500 * time.Millisecond) // race condition means we don't query keys yet
return func() {
chrome.AwaitExecute(t, c.ctx, `window.__client.stopClient();`)
}
Expand Down
8 changes: 4 additions & 4 deletions tests/membership_acls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ func TestAliceBobEncryptionWorks(t *testing.T) {

// SDK testing below
// -----------------

// login both clients first, so OTKs etc are uploaded.
alice := MustLoginClient(t, clientTypeA, api.FromComplementClient(csapiAlice, "complement-crypto-password"), ss)
defer alice.Close(t)
bob := MustLoginClient(t, clientTypeB, api.FromComplementClient(csapiBob, "complement-crypto-password"), ss)
defer bob.Close(t)

// Alice starts syncing
aliceStopSyncing := alice.StartSyncing(t)
defer aliceStopSyncing()
time.Sleep(time.Second) // TODO: find another way to wait until initial sync is done

wantMsgBody := "Hello world"

Expand All @@ -68,11 +71,8 @@ func TestAliceBobEncryptionWorks(t *testing.T) {
must.Equal(t, isEncrypted, true, "room is not encrypted when it should be")

// Bob starts syncing
bob := MustLoginClient(t, clientTypeB, api.FromComplementClient(csapiBob, "complement-crypto-password"), ss)
defer bob.Close(t)
bobStopSyncing := bob.StartSyncing(t)
defer bobStopSyncing()
time.Sleep(time.Second) // TODO: find another way to wait until initial sync is done

isEncrypted, err = bob.IsRoomEncrypted(t, roomID)
must.NotError(t, "failed to check if room is encrypted", err)
Expand Down

0 comments on commit bac416c

Please sign in to comment.