Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dipu-bd committed Sep 18, 2024
1 parent 91a945a commit 67b1db1
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 74 deletions.
23 changes: 12 additions & 11 deletions test/random/random_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Iterable<int> testGenerator() sync* {
}
}

@pragma('vm:entry-point')
void nextSeedIsolate(SendPort port) {
port.send(Generators.$nextSeed());
}

var testRandom = HashlibRandom.generator(testGenerator().iterator);

void runFunctionalText(HashlibRandom rand) {
Expand Down Expand Up @@ -92,18 +97,14 @@ void main() {
});

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

test('random bytes length = 0', () {
expect(randomBytes(0), []);
Expand Down
148 changes: 85 additions & 63 deletions test/random/uuid_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ import 'package:hashlib/codecs.dart';
import 'package:hashlib/src/uuid.dart';
import 'package:test/test.dart';

@pragma('vm:entry-point')
void runIsolate(inp) {
final port = inp[0] as SendPort;
switch (inp[1] as String) {
case 'v1':
return port.send(uuid.v1());
case 'v3':
return port.send(uuid.v3());
case 'v4':
return port.send(uuid.v4());
case 'v5':
return port.send(uuid.v5());
case 'v6':
return port.send(uuid.v6());
case 'v7':
return port.send(uuid.v7());
case 'v8':
return port.send(uuid.v8());
}
throw ArgumentError('Undefined version');
}

void main() {
group('UUID v1', () {
test("known value", () {
Expand All @@ -27,18 +49,18 @@ void main() {
});

test('uniqueness with isolates', () async {
final seeds = await Future.wait(List.generate(
1000,
final receiver = ReceivePort();
await Future.wait(List.generate(
100,
(_) => Isolate.spawn(
(e) => {},
null,
runIsolate,
[receiver.sendPort, 'v1'],
errorsAreFatal: true,
).then((value) {
return uuid.v1();
}),
),
));
expect(seeds.toSet().length, 1000);
}, tags: ['vm-only']);
final items = await receiver.take(100).toList();
expect(items.toSet().length, 100);
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
});

group('UUID v3', () {
Expand All @@ -58,18 +80,18 @@ void main() {
});

test('uniqueness with isolates', () async {
final seeds = await Future.wait(List.generate(
1000,
final receiver = ReceivePort();
await Future.wait(List.generate(
100,
(_) => Isolate.spawn(
(e) => {},
null,
runIsolate,
[receiver.sendPort, 'v3'],
errorsAreFatal: true,
).then((value) {
return uuid.v3();
}),
),
));
expect(seeds.toSet().length, 1000);
}, tags: ['vm-only']);
final items = await receiver.take(100).toList();
expect(items.toSet().length, 100);
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
});

group('UUID v4', () {
Expand All @@ -89,18 +111,18 @@ void main() {
});

test('uniqueness with isolates', () async {
final seeds = await Future.wait(List.generate(
1000,
final receiver = ReceivePort();
await Future.wait(List.generate(
100,
(_) => Isolate.spawn(
(e) => {},
null,
runIsolate,
[receiver.sendPort, 'v4'],
errorsAreFatal: true,
).then((value) {
return uuid.v4();
}),
),
));
expect(seeds.toSet().length, 1000);
}, tags: ['vm-only']);
final items = await receiver.take(100).toList();
expect(items.toSet().length, 100);
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
});

group('UUID v5', () {
Expand All @@ -120,18 +142,18 @@ void main() {
});

test('uniqueness with isolates', () async {
final seeds = await Future.wait(List.generate(
1000,
final receiver = ReceivePort();
await Future.wait(List.generate(
100,
(_) => Isolate.spawn(
(e) => {},
null,
runIsolate,
[receiver.sendPort, 'v5'],
errorsAreFatal: true,
).then((value) {
return uuid.v5();
}),
),
));
expect(seeds.toSet().length, 1000);
}, tags: ['vm-only']);
final items = await receiver.take(100).toList();
expect(items.toSet().length, 100);
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
});

group('UUID v6', () {
Expand All @@ -152,18 +174,18 @@ void main() {
});

test('uniqueness with isolates', () async {
final seeds = await Future.wait(List.generate(
1000,
final receiver = ReceivePort();
await Future.wait(List.generate(
100,
(_) => Isolate.spawn(
(e) => {},
null,
runIsolate,
[receiver.sendPort, 'v6'],
errorsAreFatal: true,
).then((value) {
return uuid.v6();
}),
),
));
expect(seeds.toSet().length, 1000);
}, tags: ['vm-only']);
final items = await receiver.take(100).toList();
expect(items.toSet().length, 100);
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
});

group('UUID v7', () {
Expand All @@ -184,18 +206,18 @@ void main() {
});

test('uniqueness with isolates', () async {
final seeds = await Future.wait(List.generate(
1000,
final receiver = ReceivePort();
await Future.wait(List.generate(
100,
(_) => Isolate.spawn(
(e) => {},
null,
runIsolate,
[receiver.sendPort, 'v7'],
errorsAreFatal: true,
).then((value) {
return uuid.v7();
}),
),
));
expect(seeds.toSet().length, 1000);
}, tags: ['vm-only']);
final items = await receiver.take(100).toList();
expect(items.toSet().length, 100);
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
});

group('UUID v8', () {
Expand Down Expand Up @@ -234,18 +256,18 @@ void main() {
});

test('uniqueness with isolates', () async {
final seeds = await Future.wait(List.generate(
1000,
final receiver = ReceivePort();
await Future.wait(List.generate(
100,
(_) => Isolate.spawn(
(e) => {},
null,
runIsolate,
[receiver.sendPort, 'v8'],
errorsAreFatal: true,
).then((value) {
return uuid.v8();
}),
),
));
expect(seeds.toSet().length, 1000);
}, tags: ['vm-only']);
final items = await receiver.take(100).toList();
expect(items.toSet().length, 100);
}, tags: ['vm-only'], timeout: Timeout(Duration(minutes: 5)));
});

group('NamespaceValue', () {
Expand Down

0 comments on commit 67b1db1

Please sign in to comment.