Skip to content

Commit 9695542

Browse files
author
Kagamihara Nadeshiko
committed
Added some tests for ConnectablePort
Specifically ones that are related to causality graph and `ConnectablePort` - that is, declaring `ConnectablePort` in a mutation should not create dependency between them, but connection between ports should.
1 parent 641ce7a commit 9695542

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

__tests__/mutations.test.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
Timer,
55
OutPort,
66
InPort,
7-
TimeValue
7+
TimeValue,
8+
IOPort
89
} from "../src/core/internal";
910

1011
class Source extends Reactor {
@@ -189,3 +190,60 @@ describe("Creating reactors at runtime", function () {
189190
// });
190191

191192
// });
193+
describe("Test the result from refactor-canconnect: referencing ConnectablePort should not introduce any change in the causality graph", () => {
194+
class InnocentReactor extends Reactor {
195+
public inp = new InPort<never>(this);
196+
public outp = new OutPort<never>(this);
197+
public cip = new InPort<never>(this);
198+
public oip = new OutPort<never>(this);
199+
public child = new (class InnocentChild extends Reactor {
200+
public oip = new OutPort<never>(this);
201+
constructor(parent: InnocentReactor) {
202+
super(parent);
203+
}
204+
})(this);
205+
206+
constructor(parent: TestApp) {
207+
super(parent);
208+
209+
this.addMutation(
210+
[this.startup],
211+
[
212+
this.inp,
213+
this.writable(this.outp),
214+
this.cip.asConnectable(),
215+
this.oip.asConnectable(),
216+
this.child.oip.asConnectable()
217+
],
218+
function (this, a0, a1, a2, a3, a4) {
219+
// This is current failing as we disallow direct feedthrough. Nevertheless I'm unsure why that is the case as of now?
220+
// this.connect(a2, a3);
221+
this.connect(a2, a4);
222+
}
223+
);
224+
}
225+
}
226+
227+
class TestApp extends App {
228+
public child = new InnocentReactor(this);
229+
constructor(done: () => void) {
230+
super(undefined, undefined, undefined, () => {
231+
const mut = this.child["_mutations"][1]; // M0 is the shutdown mutation; M1 is our mutation
232+
const pg = this._getPrecedenceGraph();
233+
// child.oip should be an island in the causality graph
234+
expect(pg.getUpstreamNeighbors(this.child.oip).size).toBe(0);
235+
expect(pg.getDownstreamNeighbors(this.child.oip).size).toBe(0);
236+
// The only dependency child.child.oip should have is child.cip
237+
expect(pg.getUpstreamNeighbors(this.child.child.oip).size).toBe(1);
238+
expect(
239+
pg.getUpstreamNeighbors(this.child.child.oip).has(this.child.cip)
240+
).toBeTruthy();
241+
done();
242+
});
243+
}
244+
}
245+
test("test dependencies", (done) => {
246+
const tapp = new TestApp(done);
247+
tapp._start();
248+
});
249+
});

0 commit comments

Comments
 (0)