Skip to content

Commit bfa0156

Browse files
author
Kagamihara Nadeshiko
committed
Added a bonus test for connection that reflects bugs in the current logic
1 parent 9695542 commit bfa0156

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

__tests__/connection.bonus.test.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import {App, InPort, OutPort, Reactor} from "../src/core/internal";
2+
3+
// Readers might wonder why this test case exist;
4+
// This is mainly because in the past, we assume direct feedthrough is forbidden, and will not establish the connection if we try to do so. However, it is possible that such a thing happen without introducing any causality issue.
5+
describe("Direct feedthrough without causality issue", () => {
6+
class BigReactor extends App {
7+
public children: SmallReactor;
8+
9+
constructor() {
10+
super(undefined, false, false);
11+
this.children = new SmallReactor(this);
12+
}
13+
}
14+
15+
class SmallReactor extends Reactor {
16+
public inp: InPort<number>;
17+
public outp: OutPort<number>;
18+
19+
constructor(parent: Reactor) {
20+
super(parent);
21+
this.inp = new InPort(this);
22+
this.outp = new OutPort(this);
23+
this.addMutation(
24+
[this.startup],
25+
[this.inp, this.outp],
26+
function (this, inp, outp) {
27+
it("test", () => {
28+
expect(this.getReactor().canConnect(inp, outp)).toBeFalsy();
29+
});
30+
}
31+
);
32+
}
33+
}
34+
35+
const root = new BigReactor();
36+
root._start();
37+
});
38+
39+
describe("Causality loop that can't be detected by only checking local graph", () => {
40+
class FeedThrougher extends Reactor {
41+
public inp = new InPort(this);
42+
public outp = new OutPort(this);
43+
44+
constructor(parent: Reactor) {
45+
super(parent);
46+
this.addReaction(
47+
[this.inp],
48+
[this.inp, this.writable(this.outp)],
49+
function (this, inp, outp) {
50+
// nop troll
51+
}
52+
);
53+
}
54+
}
55+
56+
class Looper extends Reactor {
57+
public leftChild = new FeedThrougher(this);
58+
public rightChild = new FeedThrougher(this);
59+
60+
public inp = new InPort(this);
61+
public outp = new OutPort(this);
62+
63+
constructor(parent: Reactor) {
64+
super(parent);
65+
this.addMutation(
66+
[this.startup],
67+
[
68+
this.inp.asConnectable(),
69+
this.outp.asConnectable(),
70+
this.leftChild.inp.asConnectable(),
71+
this.leftChild.outp.asConnectable(),
72+
this.rightChild.inp.asConnectable(),
73+
this.rightChild.outp.asConnectable()
74+
],
75+
function (this, inp, outp, inp_lc, outp_lc, inp_rc, outp_rc) {
76+
this.connect(inp, inp_lc);
77+
this.connect(outp_rc, outp);
78+
}
79+
);
80+
}
81+
}
82+
83+
class TestApp extends App {
84+
public child = new Looper(this);
85+
86+
constructor() {
87+
super(undefined, undefined, undefined, () => {});
88+
this._connect(this.child.outp, this.child.inp);
89+
it("Test a connection that would create zero delay loop cannot be made", () => {
90+
expect(
91+
this.canConnect(this.child.leftChild.outp, this.child.rightChild.inp)
92+
).toBeTruthy();
93+
});
94+
}
95+
}
96+
97+
const app = new TestApp();
98+
app._start();
99+
});

0 commit comments

Comments
 (0)