-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1925 from lf-lang/ts-cyclic-dependencies
Handling cyclic dependencies for TypeScript federated execution
- Loading branch information
Showing
18 changed files
with
300 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
test/TypeScript/src/federated/DistributedCountPhysicalAfterDelay.lf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Test a distributed system where a federation receives messages only over connections that are | ||
* marked 'physical' (using the ~> arrow) with an after delay. The receiver verifies that the after | ||
* delay is correctly imposed. | ||
* | ||
* @author Edward A. Lee | ||
* @author Soroush Bateni | ||
* @author Byeong-gil Jun | ||
*/ | ||
target TypeScript | ||
|
||
import Count from "../lib/Count.lf" | ||
|
||
reactor Print { | ||
input inp: number | ||
state c: number = 1 | ||
|
||
reaction(inp) {= | ||
const elapsedTime = util.getElapsedLogicalTime(); | ||
console.log(`At time ${elapsedTime}, received ${inp}`); | ||
if (inp !== c) { | ||
util.requestErrorStop(`ERROR: Expected to receive ${c}.`); | ||
} | ||
if (!elapsedTime.isLaterThan(TimeValue.msec(600))) { | ||
util.requestErrorStop(`ERROR: Expected received time to be strictly greater than ${TimeValue.msec(600)}`); | ||
} | ||
c++; | ||
console.log(`c = ${c}`); | ||
util.requestStop(); | ||
=} | ||
|
||
reaction(shutdown) {= | ||
if (c !== 2) { | ||
util.requestErrorStop(`ERROR: Expected to receive 1 item. Received ${c - 1}.`); | ||
} else { | ||
console.log("SUCCESS: Successfully received 1 item."); | ||
} | ||
=} | ||
} | ||
|
||
federated reactor at localhost { | ||
c = new Count(offset = 200 msec, period=0) | ||
p = new Print() | ||
c.out ~> p.inp after 400 msec // Indicating a 'physical' connection with a 400 msec after delay. | ||
} |
64 changes: 64 additions & 0 deletions
64
test/TypeScript/src/federated/LoopDistributedCentralized.lf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* This tests a feedback loop with physical actions and centralized coordination. | ||
* | ||
* @author Edward A. Lee | ||
* @author Hokeun Kim | ||
*/ | ||
target TypeScript { | ||
timeout: 5 sec | ||
} | ||
|
||
reactor Looper(incr: number = 1, delay: time = 0 msec) { | ||
input inp: number | ||
output out: number | ||
physical action a(delay) | ||
state count: number = 0 | ||
|
||
preamble {= | ||
let stop = false; | ||
// Function to trigger an action once every second. | ||
function ping(act: any) { | ||
if (!stop) { | ||
console.log("Scheduling action."); | ||
act.schedule(0, null); | ||
setTimeout(ping, 1000, act); | ||
} | ||
} | ||
=} | ||
|
||
reaction(startup) -> a {= | ||
// Start the ping function for triggering an action every second. | ||
console.log("Starting ping function."); | ||
ping(actions.a); | ||
=} | ||
|
||
reaction(a) -> out {= | ||
out = count; | ||
count += incr; | ||
=} | ||
|
||
reaction(inp) {= | ||
let logical = util.getCurrentLogicalTime(); | ||
let physical = util.getCurrentPhysicalTime(); | ||
|
||
let time_lag = physical.subtract(logical); | ||
|
||
console.log("Received " + inp + ". Logical time is behind physical time by " + time_lag + "."); | ||
=} | ||
|
||
reaction(shutdown) {= | ||
console.log("******* Shutdown invoked."); | ||
// Stop the ping function that is scheduling actions. | ||
stop = true; | ||
if (count != 5 * incr) { | ||
util.requestErrorStop("Failed to receive all five expected inputs."); | ||
} | ||
=} | ||
} | ||
|
||
federated reactor LoopDistributedCentralized(delay: time = 0) { | ||
left = new Looper() | ||
right = new Looper(incr=-1) | ||
left.out -> right.inp | ||
right.out -> left.inp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* This tests a feedback loop with physical actions and centralized coordination. | ||
* | ||
* @author Edward A. Lee | ||
* @author Hokeun Kim | ||
*/ | ||
target TypeScript { | ||
timeout: 5 sec, | ||
coordination-options: { | ||
advance-message-interval: 100 msec | ||
} | ||
} | ||
|
||
reactor Looper(incr: number = 1, delay: time = 0 msec) { | ||
input inp: number | ||
input inp2: number | ||
output out: number | ||
output out2: number | ||
physical action a(delay) | ||
state count: number = 0 | ||
timer t(0, 1 sec) | ||
|
||
preamble {= | ||
let stop = false; | ||
// Function to trigger an action once every second. | ||
function ping(act: any) { | ||
if (!stop) { | ||
console.log("Scheduling action."); | ||
act.schedule(0, null); | ||
setTimeout(ping, 1000, act); | ||
} | ||
} | ||
=} | ||
|
||
reaction(startup) -> a {= | ||
// Start the ping function for triggering an action every second. | ||
console.log("Starting ping function."); | ||
ping(actions.a); | ||
=} | ||
|
||
reaction(a) -> out, out2 {= | ||
if (count % 2 == 0) { | ||
out = count; | ||
} else { | ||
out2 = count; | ||
} | ||
count += incr; | ||
=} | ||
|
||
reaction(inp) {= | ||
console.log("Received " + inp + " on inp at logical time " + util.getElapsedLogicalTime() + "."); | ||
=} | ||
|
||
reaction(inp2) {= | ||
console.log("Received " + inp2 + " on inp2 at logical time " + util.getElapsedLogicalTime() + "."); | ||
=} | ||
|
||
reaction(t) {= | ||
console.log("Timer triggered at logical time " + util.getElapsedLogicalTime() + "."); | ||
=} | ||
|
||
reaction(shutdown) {= | ||
console.log("******* Shutdown invoked."); | ||
// Stop the ping function that is scheduling actions. | ||
stop = true; | ||
if (count != 5 * incr) { | ||
util.requestErrorStop("Failed to receive all five expected inputs."); | ||
} | ||
=} | ||
} | ||
|
||
federated reactor(delay: time = 0) { | ||
left = new Looper() | ||
right = new Looper(incr=-1) | ||
left.out -> right.inp | ||
right.out -> left.inp | ||
right.out2 -> left.inp2 | ||
left.out2 -> right.inp2 | ||
} |
Oops, something went wrong.