Skip to content

Commit 67b1db1

Browse files
committed
Fix tests
1 parent 91a945a commit 67b1db1

File tree

2 files changed

+97
-74
lines changed

2 files changed

+97
-74
lines changed

test/random/random_test.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Iterable<int> testGenerator() sync* {
1717
}
1818
}
1919

20+
@pragma('vm:entry-point')
21+
void nextSeedIsolate(SendPort port) {
22+
port.send(Generators.$nextSeed());
23+
}
24+
2025
var testRandom = HashlibRandom.generator(testGenerator().iterator);
2126

2227
void runFunctionalText(HashlibRandom rand) {
@@ -92,18 +97,14 @@ void main() {
9297
});
9398

9499
test('seed generator uniqueness with isolates', () async {
95-
final seeds = await Future.wait(List.generate(
96-
1000,
97-
(_) => Isolate.spawn(
98-
(e) => {},
99-
null,
100-
errorsAreFatal: true,
101-
).then((value) {
102-
return Generators.$nextSeed();
103-
}),
100+
final receiver = ReceivePort();
101+
await Future.wait(List.generate(
102+
100,
103+
(_) => Isolate.spawn(nextSeedIsolate, receiver.sendPort),
104104
));
105-
expect(seeds.toSet().length, 1000);
106-
}, tags: ['vm-only']);
105+
final seeds = await receiver.take(100).toList();
106+
expect(seeds.toSet().length, 100);
107+
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
107108

108109
test('random bytes length = 0', () {
109110
expect(randomBytes(0), []);

test/random/uuid_test.dart

Lines changed: 85 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ import 'package:hashlib/codecs.dart';
88
import 'package:hashlib/src/uuid.dart';
99
import 'package:test/test.dart';
1010

11+
@pragma('vm:entry-point')
12+
void runIsolate(inp) {
13+
final port = inp[0] as SendPort;
14+
switch (inp[1] as String) {
15+
case 'v1':
16+
return port.send(uuid.v1());
17+
case 'v3':
18+
return port.send(uuid.v3());
19+
case 'v4':
20+
return port.send(uuid.v4());
21+
case 'v5':
22+
return port.send(uuid.v5());
23+
case 'v6':
24+
return port.send(uuid.v6());
25+
case 'v7':
26+
return port.send(uuid.v7());
27+
case 'v8':
28+
return port.send(uuid.v8());
29+
}
30+
throw ArgumentError('Undefined version');
31+
}
32+
1133
void main() {
1234
group('UUID v1', () {
1335
test("known value", () {
@@ -27,18 +49,18 @@ void main() {
2749
});
2850

2951
test('uniqueness with isolates', () async {
30-
final seeds = await Future.wait(List.generate(
31-
1000,
52+
final receiver = ReceivePort();
53+
await Future.wait(List.generate(
54+
100,
3255
(_) => Isolate.spawn(
33-
(e) => {},
34-
null,
56+
runIsolate,
57+
[receiver.sendPort, 'v1'],
3558
errorsAreFatal: true,
36-
).then((value) {
37-
return uuid.v1();
38-
}),
59+
),
3960
));
40-
expect(seeds.toSet().length, 1000);
41-
}, tags: ['vm-only']);
61+
final items = await receiver.take(100).toList();
62+
expect(items.toSet().length, 100);
63+
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
4264
});
4365

4466
group('UUID v3', () {
@@ -58,18 +80,18 @@ void main() {
5880
});
5981

6082
test('uniqueness with isolates', () async {
61-
final seeds = await Future.wait(List.generate(
62-
1000,
83+
final receiver = ReceivePort();
84+
await Future.wait(List.generate(
85+
100,
6386
(_) => Isolate.spawn(
64-
(e) => {},
65-
null,
87+
runIsolate,
88+
[receiver.sendPort, 'v3'],
6689
errorsAreFatal: true,
67-
).then((value) {
68-
return uuid.v3();
69-
}),
90+
),
7091
));
71-
expect(seeds.toSet().length, 1000);
72-
}, tags: ['vm-only']);
92+
final items = await receiver.take(100).toList();
93+
expect(items.toSet().length, 100);
94+
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
7395
});
7496

7597
group('UUID v4', () {
@@ -89,18 +111,18 @@ void main() {
89111
});
90112

91113
test('uniqueness with isolates', () async {
92-
final seeds = await Future.wait(List.generate(
93-
1000,
114+
final receiver = ReceivePort();
115+
await Future.wait(List.generate(
116+
100,
94117
(_) => Isolate.spawn(
95-
(e) => {},
96-
null,
118+
runIsolate,
119+
[receiver.sendPort, 'v4'],
97120
errorsAreFatal: true,
98-
).then((value) {
99-
return uuid.v4();
100-
}),
121+
),
101122
));
102-
expect(seeds.toSet().length, 1000);
103-
}, tags: ['vm-only']);
123+
final items = await receiver.take(100).toList();
124+
expect(items.toSet().length, 100);
125+
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
104126
});
105127

106128
group('UUID v5', () {
@@ -120,18 +142,18 @@ void main() {
120142
});
121143

122144
test('uniqueness with isolates', () async {
123-
final seeds = await Future.wait(List.generate(
124-
1000,
145+
final receiver = ReceivePort();
146+
await Future.wait(List.generate(
147+
100,
125148
(_) => Isolate.spawn(
126-
(e) => {},
127-
null,
149+
runIsolate,
150+
[receiver.sendPort, 'v5'],
128151
errorsAreFatal: true,
129-
).then((value) {
130-
return uuid.v5();
131-
}),
152+
),
132153
));
133-
expect(seeds.toSet().length, 1000);
134-
}, tags: ['vm-only']);
154+
final items = await receiver.take(100).toList();
155+
expect(items.toSet().length, 100);
156+
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
135157
});
136158

137159
group('UUID v6', () {
@@ -152,18 +174,18 @@ void main() {
152174
});
153175

154176
test('uniqueness with isolates', () async {
155-
final seeds = await Future.wait(List.generate(
156-
1000,
177+
final receiver = ReceivePort();
178+
await Future.wait(List.generate(
179+
100,
157180
(_) => Isolate.spawn(
158-
(e) => {},
159-
null,
181+
runIsolate,
182+
[receiver.sendPort, 'v6'],
160183
errorsAreFatal: true,
161-
).then((value) {
162-
return uuid.v6();
163-
}),
184+
),
164185
));
165-
expect(seeds.toSet().length, 1000);
166-
}, tags: ['vm-only']);
186+
final items = await receiver.take(100).toList();
187+
expect(items.toSet().length, 100);
188+
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
167189
});
168190

169191
group('UUID v7', () {
@@ -184,18 +206,18 @@ void main() {
184206
});
185207

186208
test('uniqueness with isolates', () async {
187-
final seeds = await Future.wait(List.generate(
188-
1000,
209+
final receiver = ReceivePort();
210+
await Future.wait(List.generate(
211+
100,
189212
(_) => Isolate.spawn(
190-
(e) => {},
191-
null,
213+
runIsolate,
214+
[receiver.sendPort, 'v7'],
192215
errorsAreFatal: true,
193-
).then((value) {
194-
return uuid.v7();
195-
}),
216+
),
196217
));
197-
expect(seeds.toSet().length, 1000);
198-
}, tags: ['vm-only']);
218+
final items = await receiver.take(100).toList();
219+
expect(items.toSet().length, 100);
220+
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
199221
});
200222

201223
group('UUID v8', () {
@@ -234,18 +256,18 @@ void main() {
234256
});
235257

236258
test('uniqueness with isolates', () async {
237-
final seeds = await Future.wait(List.generate(
238-
1000,
259+
final receiver = ReceivePort();
260+
await Future.wait(List.generate(
261+
100,
239262
(_) => Isolate.spawn(
240-
(e) => {},
241-
null,
263+
runIsolate,
264+
[receiver.sendPort, 'v8'],
242265
errorsAreFatal: true,
243-
).then((value) {
244-
return uuid.v8();
245-
}),
266+
),
246267
));
247-
expect(seeds.toSet().length, 1000);
248-
}, tags: ['vm-only']);
268+
final items = await receiver.take(100).toList();
269+
expect(items.toSet().length, 100);
270+
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
249271
});
250272

251273
group('NamespaceValue', () {

0 commit comments

Comments
 (0)