Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: test/registry_test.dart

Issue 1030313003: pkg/isolate: fix test library names and group tests (Closed) Base URL: https://github.com/dart-lang/isolate.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/ports_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart.pkg.isolate.test.registry; 5 library isolate.test.registry_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 import 'package:isolate/isolate_runner.dart'; 10 import 'package:isolate/isolate_runner.dart';
11 import 'package:isolate/registry.dart'; 11 import 'package:isolate/registry.dart';
12 12
13 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
14 14
15 const MS = const Duration(milliseconds: 1); 15 const MS = const Duration(milliseconds: 1);
16 16
17 void main() { 17 void main() {
18 testLookup(); 18 group('lookup', testLookup);
19 testAddLookup(); 19 group('AddLookup', testAddLookup);
20 testAddRemoveTags(); 20 group('AddRemoveTags', testAddRemoveTags);
21 testRemove(); 21 group('Remove', testRemove);
22 testCrossIsolate(); 22 group('CrossIsolate', testCrossIsolate);
23 testTimeout(); 23 group('Timeout', testTimeout);
24 testMultiRegistry(); 24 group('MultiRegistry', testMultiRegistry);
25 testObjectsAndTags(); 25 group('ObjectsAndTags', testObjectsAndTags);
26 } 26 }
27 27
28 class Oddity { 28 class Oddity {
29 static const int EVEN = 0; 29 static const int EVEN = 0;
30 static const int ODD = 1; 30 static const int ODD = 1;
31 } 31 }
32 32
33 Future<List> waitAll(int n, Future action(int n)) { 33 Future<List> waitAll(int n, Future action(int n)) {
34 return Future.wait(new Iterable.generate(n, action)); 34 return Future.wait(new Iterable.generate(n, action));
35 } 35 }
36 36
37 void testLookup() { 37 void testLookup() {
38 test("lookupAll", () { 38 test("All", () {
39 RegistryManager regman = new RegistryManager(); 39 RegistryManager regman = new RegistryManager();
40 Registry registry = regman.registry; 40 Registry registry = regman.registry;
41 return waitAll(10, (i) { 41 return waitAll(10, (i) {
42 var element = new Element(i); 42 var element = new Element(i);
43 var tag = i.isEven ? Oddity.EVEN : Oddity.ODD; 43 var tag = i.isEven ? Oddity.EVEN : Oddity.ODD;
44 return registry.add(element, tags: [tag]); 44 return registry.add(element, tags: [tag]);
45 }).then((_) { 45 }).then((_) {
46 return registry.lookup(); 46 return registry.lookup();
47 }).then((all) { 47 }).then((all) {
48 expect(all.length, 10); 48 expect(all.length, 10);
49 expect(all.map((v) => v.id).toList()..sort(), 49 expect(all.map((v) => v.id).toList()..sort(),
50 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); 50 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
51 }) 51 })
52 .whenComplete(regman.close); 52 .whenComplete(regman.close);
53 }); 53 });
54 54
55 test("lookupOdd", () { 55 test("Odd", () {
56 RegistryManager regman = new RegistryManager(); 56 RegistryManager regman = new RegistryManager();
57 Registry registry = regman.registry; 57 Registry registry = regman.registry;
58 return waitAll(10, (i) { 58 return waitAll(10, (i) {
59 var element = new Element(i); 59 var element = new Element(i);
60 var tag = i.isEven ? Oddity.EVEN : Oddity.ODD; 60 var tag = i.isEven ? Oddity.EVEN : Oddity.ODD;
61 return registry.add(element, tags: [tag]); 61 return registry.add(element, tags: [tag]);
62 }).then((_) { 62 }).then((_) {
63 return registry.lookup(tags:[Oddity.ODD]); 63 return registry.lookup(tags:[Oddity.ODD]);
64 }).then((all) { 64 }).then((all) {
65 expect(all.length, 5); 65 expect(all.length, 5);
66 expect(all.map((v) => v.id).toList()..sort(), 66 expect(all.map((v) => v.id).toList()..sort(),
67 [1, 3, 5, 7, 9]); 67 [1, 3, 5, 7, 9]);
68 }) 68 })
69 .whenComplete(regman.close); 69 .whenComplete(regman.close);
70 }); 70 });
71 71
72 test("lookupMax", () { 72 test("Max", () {
73 RegistryManager regman = new RegistryManager(); 73 RegistryManager regman = new RegistryManager();
74 Registry registry = regman.registry; 74 Registry registry = regman.registry;
75 return waitAll(10, (i) { 75 return waitAll(10, (i) {
76 var element = new Element(i); 76 var element = new Element(i);
77 var tag = i.isEven ? Oddity.EVEN : Oddity.ODD; 77 var tag = i.isEven ? Oddity.EVEN : Oddity.ODD;
78 return registry.add(element, tags: [tag]); 78 return registry.add(element, tags: [tag]);
79 }).then((_) { 79 }).then((_) {
80 return registry.lookup(max: 5); 80 return registry.lookup(max: 5);
81 }).then((all) { 81 }).then((all) {
82 expect(all.length, 5); 82 expect(all.length, 5);
83 }) 83 })
84 .whenComplete(regman.close); 84 .whenComplete(regman.close);
85 }); 85 });
86 86
87 test("lookupMultiTag", () { 87 test("MultiTag", () {
88 RegistryManager regman = new RegistryManager(); 88 RegistryManager regman = new RegistryManager();
89 Registry registry = regman.registry; 89 Registry registry = regman.registry;
90 return waitAll(25, (i) { 90 return waitAll(25, (i) {
91 var element = new Element(i); 91 var element = new Element(i);
92 // Collect all numbers dividing i. 92 // Collect all numbers dividing i.
93 var tags = [i]; 93 var tags = [i];
94 for (int j = 2; j < 25; j++) { 94 for (int j = 2; j < 25; j++) {
95 if (i % j == 0) tags.add(j); 95 if (i % j == 0) tags.add(j);
96 } 96 }
97 return registry.add(element, tags: tags); 97 return registry.add(element, tags: tags);
98 }).then((_) { 98 }).then((_) {
99 return registry.lookup(tags: [2, 3]); 99 return registry.lookup(tags: [2, 3]);
100 }).then((all) { 100 }).then((all) {
101 expect(all.length, 5); 101 expect(all.length, 5);
102 expect(all.map((v) => v.id).toList()..sort(), 102 expect(all.map((v) => v.id).toList()..sort(),
103 [0, 6, 12, 18, 24]); 103 [0, 6, 12, 18, 24]);
104 }) 104 })
105 .whenComplete(regman.close); 105 .whenComplete(regman.close);
106 }); 106 });
107 107
108 test("lookupMultiTagMax", () { 108 test("MultiTagMax", () {
109 RegistryManager regman = new RegistryManager(); 109 RegistryManager regman = new RegistryManager();
110 Registry registry = regman.registry; 110 Registry registry = regman.registry;
111 return waitAll(25, (i) { 111 return waitAll(25, (i) {
112 var element = new Element(i); 112 var element = new Element(i);
113 // Collect all numbers dividing i. 113 // Collect all numbers dividing i.
114 var tags = [i]; 114 var tags = [i];
115 for (int j = 2; j < 25; j++) { 115 for (int j = 2; j < 25; j++) {
116 if (i % j == 0) tags.add(j); 116 if (i % j == 0) tags.add(j);
117 } 117 }
118 return registry.add(element, tags: tags); 118 return registry.add(element, tags: tags);
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 530 }
531 531
532 class Element { 532 class Element {
533 final int id; 533 final int id;
534 Element(this.id); 534 Element(this.id);
535 int get hashCode => id; 535 int get hashCode => id;
536 bool operator ==(Object other) => other is Element && id == other.id; 536 bool operator ==(Object other) => other is Element && id == other.id;
537 } 537 }
538 538
539 void topLevelFunction() {} 539 void topLevelFunction() {}
OLDNEW
« no previous file with comments | « test/ports_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698