Skip to content

Commit 186977d

Browse files
committed
Updated info test and moved util to helper
1 parent da70238 commit 186977d

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

packages/database-compat/test/info.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ describe('.info Tests', function () {
130130

131131
await ea.promise;
132132

133-
expect(typeof offsets[0]).to.equal('number');
134-
expect(offsets[0]).to.be.greaterThanOrEqual(0); // There is no way for us to guarantee that the latency will be exactly 0.
133+
expect(offsets[0]).to.be.a('number');
135134

136135
// Make sure push still works
137136
ref.push();

packages/database/test/exp/integration.test.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
getFreshRepo,
4747
getRWRefs,
4848
waitFor,
49+
waitUntil,
4950
writeAndValidate
5051
} from '../helpers/util';
5152

@@ -143,19 +144,6 @@ describe('Database@exp Tests', () => {
143144
);
144145
});
145146

146-
async function waitUntil(cb: () => boolean, maxRetries = 5) {
147-
let count = 1;
148-
return new Promise((resolve, reject) => {
149-
if (cb()) {
150-
resolve(true);
151-
} else {
152-
if (count++ === maxRetries) {
153-
reject('waited too many times for conditional to be true');
154-
}
155-
}
156-
});
157-
}
158-
159147
it('[smoketest] - calls onValue() listener when get() is called on a parent node', async () => {
160148
// Test that when get() is pending on a parent node, and then onValue is called on a child node, that after the get() comes back, the onValue() listener fires.
161149
const db = getDatabase(defaultApp);
@@ -170,9 +158,9 @@ describe('Database@exp Tests', () => {
170158
});
171159
await waitUntil(() => {
172160
// Because this is a test reliant on network latency, it can be difficult to reproduce. There are situations when get() resolves immediately, and the above behavior is not observed.
173-
let resolved = false;
174-
get(readerRef).then(() => (resolved = true));
175-
return !resolved;
161+
let pending = false;
162+
get(readerRef).then(() => (pending = true));
163+
return !pending;
176164
});
177165
const childPath = child(readerRef, 'foo1');
178166
const ec = EventAccumulatorFactory.waitsForExactCount(1);

packages/database/test/helpers/util.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,17 @@ export async function writeAndValidate(
130130
const [snap] = await ec.promise;
131131
expect(snap.val()).to.deep.eq(toWrite);
132132
}
133+
134+
// Waits until callback function returns true
135+
export async function waitUntil(cb: () => boolean, maxRetries = 5) {
136+
let count = 1;
137+
return new Promise((resolve, reject) => {
138+
if (cb()) {
139+
resolve(true);
140+
} else {
141+
if (count++ === maxRetries) {
142+
reject('waited too many times for conditional to be true');
143+
}
144+
}
145+
});
146+
}

0 commit comments

Comments
 (0)