Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install the RTI while testing and Prevent unintended tag advancement #152

Merged
merged 7 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
repository: lf-lang/lingua-franca
ref: ${{ env.lingua-franca-ref }}
fetch-depth: 0
submodules: true
- name: Prepare build environment
uses: ./.github/actions/prepare-build-env
- name: Setup Node.js environment
Expand All @@ -41,6 +42,9 @@ jobs:
node-version: 18
- name: Install pnpm
run: npm i -g pnpm
- name: Install RTI
uses: ./.github/actions/install-rti
if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
- name: Perform Lingua Franca TypeScript tests
run: |
./gradlew test --tests org.lflang.tests.runtime.TypeScriptTest.* -Druntime="git://github.com/lf-lang/reactor-ts.git#${{ github.head_ref || github.ref_name }}"
2 changes: 1 addition & 1 deletion lingua-franca-ref.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master
fix-ts-federated-tests
21 changes: 12 additions & 9 deletions src/core/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,12 +915,12 @@ enum StopRequestState {
* including the current state and the tag associated with the stop requested or stop granted.
*/
class StopRequestInfo {
constructor(state: StopRequestState, tag: Tag | null) {
constructor(state: StopRequestState, tag: Tag) {
this.state = state;
this.tag = tag;
}
readonly state: StopRequestState;
readonly tag: Tag | null;
readonly tag: Tag;
}

/**
Expand Down Expand Up @@ -950,15 +950,15 @@ export class FederatedApp extends App {
* Stop request-related information
* including the current state and the tag associated with the stop requested or stop granted.
*/
private stopRequestInfo: StopRequestInfo = new StopRequestInfo(StopRequestState.NOT_SENT, null);
private stopRequestInfo: StopRequestInfo = new StopRequestInfo(StopRequestState.NOT_SENT, new Tag(TimeValue.FOREVER(), 0));

/**
* The largest time advance grant received so far from the RTI,
* or null if no time advance grant has been received yet.
* or NEVER if no time advance grant has been received yet.
* An RTI synchronized Federate cannot advance its logical time
* beyond this value.
*/
private greatestTimeAdvanceGrant: Tag | null = null;
private greatestTimeAdvanceGrant: Tag = new Tag(TimeValue.NEVER(), 0);

private upstreamFedIDs: number[] = [];
private upstreamFedDelays: TimeValue[] = [];
Expand Down Expand Up @@ -1031,16 +1031,19 @@ export class FederatedApp extends App {
* @param nextEvent
*/
protected _canProceed(nextEvent: TaggedEvent<Present>) {
let tagBarrier = null;
let tagBarrier = new Tag(TimeValue.NEVER());
// Set tag barrier using the tag when stop is requested but not granted yet.
// Otherwise, set the tagBarrier using the greated TAG.
if (this.stopRequestInfo.state === StopRequestState.SENT) {
tagBarrier = this.stopRequestInfo.tag;
if (this.upstreamFedIDs.length === 0 && tagBarrier.isSmallerThan(nextEvent.tag)) {
return false;
}
} else {
tagBarrier = this._getGreatestTimeAdvanceGrant();
}

if (tagBarrier !== null) {
if (this.upstreamFedIDs.length !== 0) {
if (tagBarrier.isSmallerThan(nextEvent.tag)) {
if (this.minDelayFromPhysicalActionToFederateOutput !== null &&
this.downstreamFedIDs.length > 0) {
Expand Down Expand Up @@ -1361,7 +1364,7 @@ export class FederatedApp extends App {

this.rtiClient.on('timeAdvanceGrant', (tag: Tag) => {
Log.debug(this, () => {return `Time Advance Grant received from RTI for ${tag}.`});
if (this.greatestTimeAdvanceGrant === null || this.greatestTimeAdvanceGrant?.isSmallerThan(tag)) {
if (this.greatestTimeAdvanceGrant.isSmallerThan(tag)) {
// Update the greatest time advance grant and immediately
// wake up _next, in case it was blocked by the old time advance grant
this.greatestTimeAdvanceGrant = tag;
Expand All @@ -1372,7 +1375,7 @@ export class FederatedApp extends App {

this.rtiClient.on('provisionalTimeAdvanceGrant', (tag: Tag) => {
Log.debug(this, () => {return `Provisional Time Advance Grant received from RTI for ${tag}.`});
if (this.greatestTimeAdvanceGrant === null || this.greatestTimeAdvanceGrant?.isSmallerThan(tag)) {
if (this.greatestTimeAdvanceGrant.isSmallerThan(tag)) {
// Update the greatest time advance grant and immediately
// wake up _next, in case it was blocked by the old time advance grant

Expand Down