Skip to content

Commit 10309d3

Browse files
committed
chore: fix weakref tests
1 parent 06f1d06 commit 10309d3

File tree

2 files changed

+50
-99
lines changed

2 files changed

+50
-99
lines changed

test-app/app/src/main/assets/app/tests/testNativeTimers.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ describe('native timer', () => {
115115
expect(!!weakRef.get()).toBe(true);
116116
clearInterval(interval);
117117
clearTimeout(timeout);
118-
gc();
119-
expect(!!weakRef.get()).toBe(false);
120-
done();
118+
// use another timeout as native weakrefs can't be gced until we leave the isolate after being used once
119+
setTimeout(() => {
120+
gc();
121+
expect(!!weakRef.get()).toBe(false);
122+
done();
123+
})
121124
}, 200);
122125
})
123126
});
Lines changed: 44 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,97 @@
11
describe("Test WeakRef ", function () {
2-
3-
it("Test if WeakRef gets cleared after gc", function () {
4-
2+
it("Test if WeakRef gets cleared after gc", function (done) {
53
__log("TEST: TestWeakRefGetsClearedAfterGC");
6-
4+
75
var wr = new WeakRef({ someProp: 12345 });
8-
6+
97
var val = wr.get().someProp;
108
expect(val).toBe(12345);
11-
129
gc();
13-
14-
var val = wr.get();
15-
expect(val).toBe(null);
16-
});
17-
18-
it("Test if WeakRef gets cleared after clear", function () {
19-
20-
__log("TEST: TestWeakRefGetsClearedAfterClear");
21-
22-
var wr = new WeakRef({ someProp: 54321 });
23-
24-
var val = wr.get().someProp;
25-
expect(val).toBe(54321);
26-
27-
wr.clear();
28-
29-
var val = wr.get();
30-
expect(val).toBe(null);
10+
11+
setTimeout(() => {
12+
gc();
13+
var val = wr.get();
14+
expect(val).toBe(undefined);
15+
done();
16+
});
3117
});
32-
33-
it("Test if WeakRef can create multiple instances", function () {
34-
18+
19+
it("Test if WeakRef can create multiple instances", function (done) {
3520
__log("TEST: TestWeakRefCanCreateMultipleInstances");
36-
37-
var target = { someProp: 54321 };
38-
39-
var wr1 = new WeakRef(target);
40-
var wr2 = new WeakRef(target);
41-
42-
target = null;
43-
44-
wr1.clear();
45-
46-
var val = wr1.get();
47-
expect(val).toBe(null);
48-
49-
val = wr2.get().someProp;
50-
expect(val).toBe(54321);
51-
});
52-
53-
it("Test if WeakRef can create multiple instances 2", function () {
5421

55-
__log("TEST: TestWeakRefCanCreateMultipleInstances2");
56-
5722
var target = { someProp: 54321 };
58-
23+
5924
var wr1 = new WeakRef(target);
6025
var wr2 = new WeakRef(target);
61-
26+
6227
target = null;
63-
gc();
64-
65-
var val1 = wr1.get();
66-
expect(val1).toBe(null);
67-
68-
var val2 = wr2.get();
69-
expect(val2).toBe(null);
28+
setTimeout(() => {
29+
gc();
30+
31+
var val1 = wr1.get();
32+
expect(val1).toBe(undefined);
33+
34+
var val2 = wr2.get();
35+
expect(val2).toBe(undefined);
36+
done();
37+
});
7038
});
71-
39+
7240
it("Test if WeakRef throws exception when constructed with wrong number of parameters", function () {
73-
74-
__log("TEST: TestWeakRefThrowsExceptionWhenConstructedWithWrongNumberOfParameters");
75-
41+
__log(
42+
"TEST: TestWeakRefThrowsExceptionWhenConstructedWithWrongNumberOfParameters"
43+
);
44+
7645
var exceptionCaught = false;
77-
try
78-
{
46+
try {
7947
new WeakRef();
80-
}
81-
catch (e)
82-
{
48+
} catch (e) {
8349
exceptionCaught = true;
8450
}
8551
expect(exceptionCaught).toBe(true);
86-
52+
8753
exceptionCaught = false;
88-
try
89-
{
54+
try {
9055
new WeakRef(1, 2);
91-
}
92-
catch (e)
93-
{
56+
} catch (e) {
9457
exceptionCaught = true;
9558
}
9659
expect(exceptionCaught).toBe(true);
97-
9860
});
9961

10062
it("Test if WeakRef throws exception when constructed with non object", function () {
101-
10263
__log("TEST: TestWeakRefThrowsExceptionWhenConstructedWithNonObject");
103-
64+
10465
var exceptionCaught = false;
105-
try
106-
{
66+
try {
10767
new WeakRef(1);
108-
}
109-
catch (e)
110-
{
68+
} catch (e) {
11169
exceptionCaught = true;
11270
}
11371
expect(exceptionCaught).toBe(true);
114-
72+
11573
exceptionCaught = false;
116-
try
117-
{
74+
try {
11875
new WeakRef(false);
119-
}
120-
catch (e)
121-
{
76+
} catch (e) {
12277
exceptionCaught = true;
12378
}
12479
expect(exceptionCaught).toBe(true);
12580

12681
exceptionCaught = false;
127-
try
128-
{
82+
try {
12983
new WeakRef(null);
130-
}
131-
catch (e)
132-
{
84+
} catch (e) {
13385
exceptionCaught = true;
13486
}
13587
expect(exceptionCaught).toBe(true);
13688

13789
exceptionCaught = false;
138-
try
139-
{
90+
try {
14091
new WeakRef(undefined);
141-
}
142-
catch (e)
143-
{
92+
} catch (e) {
14493
exceptionCaught = true;
14594
}
14695
expect(exceptionCaught).toBe(true);
14796
});
14897
});
149-

0 commit comments

Comments
 (0)