tests/index.jsView |
---|
116 | 116 … | await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
117 | 117 … | ports: [portRef2] |
118 | 118 … | })) |
119 | 119 … | this.kernel.incrementTicks(2) |
120 | | - this.kernel.send(portRef1, m) |
121 | | - return this.kernel.ports.bind('child', portRef1) |
| 120 … | + |
| 121 … | + return Promise.all([ |
| 122 … | + this.kernel.send(portRef1, m), |
| 123 … | + this.kernel.ports.bind('child', portRef1) |
| 124 … | + ]) |
122 | 125 … | } |
123 | 126 … | } |
124 | 127 … | |
125 | 128 … | const hypervisor = new Hypervisor(node.dag) |
136 | 139 … | message = root.createMessage({ |
137 | 140 … | data: 'test' |
138 | 141 … | }) |
139 | 142 … | |
140 | | - root.send(portRef1, message) |
| 143 … | + await root.send(portRef1, message) |
141 | 144 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
142 | 145 … | |
143 | 146 … | t.deepEquals(stateRoot, expectedState, 'expected state') |
144 | 147 … | |
175 | 178 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
176 | 179 … | await this.kernel.createInstance(testVMContainer2.typeId, this.kernel.createMessage({ |
177 | 180 … | ports: [portRef2] |
178 | 181 … | })) |
179 | | - this.kernel.send(portRef1, m) |
| 182 … | + await this.kernel.send(portRef1, m) |
180 | 183 … | this.kernel.incrementTicks(1) |
181 | 184 … | return this.kernel.ports.bind('child', portRef1) |
182 | 185 … | } |
183 | 186 … | } |
195 | 198 … | |
196 | 199 … | await root.ports.bind('first', portRef1) |
197 | 200 … | message = root.createMessage() |
198 | 201 … | |
199 | | - root.send(portRef1, message) |
| 202 … | + await root.send(portRef1, message) |
200 | 203 … | const stateRoot = await hypervisor.createStateRoot(Infinity) |
201 | 204 … | t.true(hasResolved, 'should resolve before generating the state root') |
202 | 205 … | |
203 | 206 … | |
286 | 289 … | |
287 | 290 … | await this.kernel.createInstance(First.typeId, message1) |
288 | 291 … | await this.kernel.createInstance(Second.typeId, message2) |
289 | 292 … | |
290 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
291 | | - this.kernel.send(portRef3, this.kernel.createMessage()) |
292 | 293 … | return Promise.all( |
| 294 … | + this.kernel.send(portRef1, this.kernel.createMessage()), |
| 295 … | + this.kernel.send(portRef3, this.kernel.createMessage()), |
293 | 296 … | this.kernel.ports.bind('two', portRef3), |
294 | 297 … | this.kernel.ports.bind('one', portRef1) |
295 | 298 … | ) |
296 | 299 … | } else if (runs === 1) { |
304 | 307 … | |
305 | 308 … | class First extends BaseContainer { |
306 | 309 … | onMessage (m) { |
307 | 310 … | this.kernel.incrementTicks(2) |
308 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 311 … | + return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
309 | 312 … | data: 'first' |
310 | 313 … | })) |
311 | 314 … | } |
312 | 315 … | |
317 | 320 … | |
318 | 321 … | class Second extends BaseContainer { |
319 | 322 … | onMessage (m) { |
320 | 323 … | this.kernel.incrementTicks(3) |
321 | | - this.kernel.send(m.fromPort, this.kernel.createMessage({ |
| 324 … | + return this.kernel.send(m.fromPort, this.kernel.createMessage({ |
322 | 325 … | data: 'second' |
323 | 326 … | })) |
324 | 327 … | } |
325 | 328 … | |
793 | 796 … | }) |
794 | 797 … | await this.kernel.createInstance(First.typeId, message1) |
795 | 798 … | return this.kernel.ports.bind('one', portRef1) |
796 | 799 … | } else { |
797 | | - this.kernel.send(one, this.kernel.createMessage()) |
798 | | - this.kernel.send(one, this.kernel.createMessage()) |
| 800 … | + return Promise.all([ |
| 801 … | + this.kernel.send(one, this.kernel.createMessage()), |
| 802 … | + this.kernel.send(one, this.kernel.createMessage()) |
| 803 … | + ]) |
799 | 804 … | } |
800 | 805 … | } |
801 | 806 … | static get typeId () { |
802 | 807 … | return 299 |
827 | 832 … | ports: [portRef2] |
828 | 833 … | })) |
829 | 834 … | |
830 | 835 … | const message = root.createMessage() |
831 | | - root.send(portRef1, message) |
| 836 … | + await root.send(portRef1, message) |
832 | 837 … | await hypervisor.createStateRoot() |
833 | | - root.send(portRef1, root.createMessage()) |
| 838 … | + await root.send(portRef1, root.createMessage()) |
834 | 839 … | await hypervisor.createStateRoot() |
835 | 840 … | t.equals(runs, 2) |
836 | 841 … | } catch (e) { |
837 | 842 … | console.log(e) |
890 | 895 … | ports: [portRef2] |
891 | 896 … | }) |
892 | 897 … | |
893 | 898 … | await this.kernel.createInstance(First.typeId, message1) |
894 | | - this.kernel.send(portRef1, this.kernel.createMessage()) |
| 899 … | + await this.kernel.send(portRef1, this.kernel.createMessage()) |
895 | 900 … | this.kernel.incrementTicks(6) |
896 | 901 … | return this.kernel.ports.bind('one', portRef1) |
897 | 902 … | } |
898 | 903 … | } |
899 | 904 … | |
900 | 905 … | class First extends BaseContainer { |
901 | 906 … | onMessage (m) { |
902 | 907 … | this.kernel.incrementTicks(2) |
903 | | - this.kernel.ports.delete('root') |
| 908 … | + return this.kernel.ports.delete('root') |
904 | 909 … | } |
905 | 910 … | static get typeId () { |
906 | 911 … | return 299 |
907 | 912 … | } |
919 | 924 … | ports: [portRef2] |
920 | 925 … | })) |
921 | 926 … | |
922 | 927 … | const message = root.createMessage() |
923 | | - root.send(portRef1, message) |
| 928 … | + await root.send(portRef1, message) |
924 | 929 … | |
925 | 930 … | const sr = await hypervisor.createStateRoot() |
926 | 931 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
927 | 932 … | await hypervisor.graph.tree(sr, Infinity, true) |
949 | 954 … | ports: [portRef2] |
950 | 955 … | })) |
951 | 956 … | |
952 | 957 … | const message = root.createMessage() |
953 | | - root.send(portRef1, message) |
| 958 … | + await root.send(portRef1, message) |
954 | 959 … | const sr = await hypervisor.createStateRoot() |
955 | 960 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
956 | 961 … | |
957 | 962 … | t.end() |
996 | 1001 … | await root.createInstance(Root.typeId, root.createMessage({ |
997 | 1002 … | ports: [portRef2] |
998 | 1003 … | })) |
999 | 1004 … | |
1000 | | - root.send(portRef1, root.createMessage()) |
| 1005 … | + await root.send(portRef1, root.createMessage()) |
1001 | 1006 … | const sr = await hypervisor.createStateRoot() |
1002 | 1007 … | |
1003 | 1008 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
1004 | 1009 … | t.end() |
1014 | 1019 … | class Root extends BaseContainer { |
1015 | 1020 … | async onMessage (m) { |
1016 | 1021 … | if (m.ports.length) { |
1017 | 1022 … | const port = this.kernel.ports.get('test1') |
1018 | | - this.kernel.send(port, m) |
| 1023 … | + await this.kernel.send(port, m) |
1019 | 1024 … | return this.kernel.ports.unbind('test1') |
1020 | 1025 … | } else { |
1021 | 1026 … | const [portRef1, portRef2] = this.kernel.ports.createChannel() |
1022 | 1027 … | await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1028 | 1033 … | await this.kernel.createInstance(Sub.typeId, this.kernel.createMessage({ |
1029 | 1034 … | ports: [portRef4] |
1030 | 1035 … | })) |
1031 | 1036 … | await this.kernel.ports.bind('test2', portRef3) |
1032 | | - this.kernel.send(portRef3, this.kernel.createMessage({ |
| 1037 … | + await this.kernel.send(portRef3, this.kernel.createMessage({ |
1033 | 1038 … | data: 'getChannel' |
1034 | 1039 … | })) |
1035 | 1040 … | } |
1036 | 1041 … | } |
1037 | 1042 … | } |
1038 | 1043 … | |
1039 | 1044 … | class Sub extends BaseContainer { |
1040 | | - onMessage (message) { |
| 1045 … | + async onMessage (message) { |
1041 | 1046 … | if (message.data === 'getChannel') { |
1042 | 1047 … | const ports = this.kernel.ports.createChannel() |
1043 | | - this.kernel.send(message.fromPort, this.kernel.createMessage({ |
| 1048 … | + await this.kernel.send(message.fromPort, this.kernel.createMessage({ |
1044 | 1049 … | data: 'bindPort', |
1045 | 1050 … | ports: [ports[1]] |
1046 | 1051 … | })) |
1047 | 1052 … | return this.kernel.ports.bind('channel', ports[0]) |
1065 | 1070 … | await root.createInstance(Root.typeId, root.createMessage({ |
1066 | 1071 … | ports: [portRef2] |
1067 | 1072 … | })) |
1068 | 1073 … | |
1069 | | - root.send(portRef1, root.createMessage()) |
| 1074 … | + await root.send(portRef1, root.createMessage()) |
1070 | 1075 … | const sr = await hypervisor.createStateRoot() |
1071 | 1076 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
1072 | 1077 … | |
1073 | 1078 … | |
1130 | 1135 … | |
1131 | 1136 … | const root = await hypervisor.createInstance(Root.typeId) |
1132 | 1137 … | |
1133 | 1138 … | const [portRef1, portRef2] = root.ports.createChannel() |
1134 | | - await root.ports.bind('first', portRef1) |
1135 | | - await root.createInstance(Root.typeId, root.createMessage({ |
1136 | | - ports: [portRef2] |
1137 | | - })) |
| 1139 … | + await Promise.all([ |
| 1140 … | + root.ports.bind('first', portRef1), |
| 1141 … | + root.createInstance(Root.typeId, root.createMessage({ |
| 1142 … | + ports: [portRef2] |
| 1143 … | + })), |
| 1144 … | + root.send(portRef1, root.createMessage()) |
| 1145 … | + ]) |
1138 | 1146 … | |
1139 | | - root.send(portRef1, root.createMessage()) |
1140 | | - |
1141 | 1147 … | const sr = await hypervisor.createStateRoot() |
1142 | 1148 … | t.deepEquals(sr, expectedSr, 'should produce the corret state root') |
1143 | 1149 … | |
1144 | | - |
1145 | | - |
1146 | | - |
1147 | 1150 … | t.end() |
1148 | 1151 … | } catch (e) { |
1149 | 1152 … | console.log(e) |
1150 | 1153 … | } |