Skip to content

Commit 137a41f

Browse files
committed
Add a small amount of tests
1 parent 9ec3729 commit 137a41f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/processes/process_system.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ProcessSystem {
100100
if(real_pid){
101101

102102
this.monitors.set(ref, {'monitor': this.current_process.pid, 'monitee': real_pid});
103-
this.pids.get(real_pid).monitors(ref);
103+
this.pids.get(real_pid).monitors.push(ref);
104104
return ref;
105105
}else{
106106
this.send(this.current_process.pid, new ErlangTypes.Tuple('DOWN', ref, pid, real_pid, Symbol.for('noproc')));
@@ -346,7 +346,7 @@ class ProcessSystem {
346346
}
347347

348348
list(){
349-
return this.pids.keys();
349+
return Array.from(this.pids.keys());
350350
}
351351

352352
make_ref(){

test/processes_test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import test from 'ava';
2+
import Processes from '../src/index.js';
3+
4+
let system = null;
5+
6+
test.beforeEach(t => {
7+
system = new Processes.ProcessSystem();
8+
});
9+
10+
test(function* testSpawn (t) {
11+
const pid = system.spawn(function*(){
12+
yield 1;
13+
});
14+
15+
t.is(system.list().length, 2);
16+
t.is(system.list()[1], pid);
17+
});
18+
19+
test(function* testSpawnLink (t) {
20+
const pid = system.spawn_link(function*(){
21+
yield 1;
22+
});
23+
24+
t.is(system.list().length, 2);
25+
t.true(system.links.get(pid).has(system.list()[0]));
26+
t.true(system.links.get(system.list()[0]).has(pid));
27+
});
28+
29+
test(function* testSpawnMonitor (t) {
30+
const [pid, ref] = system.spawn_monitor(function*(){
31+
yield 1;
32+
});
33+
34+
t.is(system.list().length, 2);
35+
t.deepEqual(system.monitors.get(ref), {'monitor': system.list()[0], 'monitee': pid});
36+
});

0 commit comments

Comments
 (0)