Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Fix test play/pause state #491

Merged
merged 3 commits into from
Feb 25, 2020
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
64 changes: 24 additions & 40 deletions packages/functional-tests/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class App {
private playPauseButton: MRE.Actor;
private playPauseText: MRE.Actor;
private runnerActors: MRE.Actor[];
private sharedActors: MRE.Actor[];
private backgroundMaterial: MRE.Material;

private testRoot: MRE.Actor;
Expand Down Expand Up @@ -113,12 +112,6 @@ export class App {
}
return this.runPromise = this.runTestHelper(user);
})
.then(() => {
if (this.playPauseButton) {
this.playPauseButton.appearance.material.color.set(0, 1, 0, 1);
this.playPauseText.text.contents = "Start";
}
})
// and log unexpected errors
.catch(err => console.log(err));
}
Expand All @@ -130,6 +123,13 @@ export class App {
const test = this.activeTest = this.activeTestFactory(this, this.baseUrl, user);
this.setOverrideText(test.expectedResultDescription);

this.testRoot = MRE.Actor.Create(this.context, {
actor: {
name: 'testRoot',
exclusiveToUser: this.exclusiveUser && this.exclusiveUser.id || undefined
}
});

let success: boolean;
try {
test.checkPermission(user);
Expand All @@ -149,20 +149,24 @@ export class App {
if (success) {
this.setOverrideText(null);
}

test.cleanup();

// Delete all actors
destroyActors(this.context.rootActors.filter(x =>
!this.runnerActors.includes(x) && !this.sharedActors.includes(x)));
}

private async stopTest() {
if (this.activeTest !== null) {
this.activeTest.stop();
await this.runPromise;
this.activeTest.cleanup();
this.activeTest = null;
this.runPromise = null;

// Delete all actors
this.testRoot?.destroy();
this.testRoot = null;

if (this.playPauseButton) {
this.playPauseButton.appearance.material.color.set(0, 1, 0, 1);
this.playPauseText.text.contents = "Start";
}
}
}

Expand Down Expand Up @@ -194,17 +198,6 @@ export class App {
const wasRunning = !!this.activeTest;
await this.stopTest();

if (this.testRoot) {
this.testRoot.destroy();
}

this.testRoot = MRE.Actor.Create(this.context, {
actor: {
name: 'testRoot',
exclusiveToUser: this.exclusiveUser && this.exclusiveUser.id || undefined
}
});

if (wasRunning) {
this.runTest(user);
}
Expand Down Expand Up @@ -251,7 +244,7 @@ export class App {
this.exclusiveUserToggle.setBehavior(MRE.ButtonBehavior)
.onButton('released', user => this.toggleExclusiveUser(user));

const floor = MRE.Actor.Create(this.context, {
MRE.Actor.Create(this.context, {
actor: {
name: 'floor',
appearance: {
Expand All @@ -267,7 +260,7 @@ export class App {
}
});

const wall = MRE.Actor.Create(this.context, {
MRE.Actor.Create(this.context, {
actor: {
name: 'wall',
appearance: {
Expand All @@ -282,8 +275,6 @@ export class App {
collider: { geometry: { shape: MRE.ColliderType.Auto } }
}
});

this.sharedActors = [this.exclusiveUserToggle, label, wall, floor];
}

private setupRunner() {
Expand All @@ -306,23 +297,16 @@ export class App {
}
});

this.testRoot = MRE.Actor.Create(this.context, {
actor: {
name: 'testRoot',
exclusiveToUser: this.exclusiveUser && this.exclusiveUser.id || undefined
}
});

if (this.params.nomenu === 'true') {
this.runnerActors = [this.contextLabel];
return;
}

// start or stop the active test
const ppMat = this.assets.createMaterial('pp', {
color: MRE.Color3.Green().toJSON()
});
const ppMesh = this.assets.createBoxMesh('playpause', 0.7, 0.3, 0.1);
const ppMat = this.assets.materials.find(m => m.name === 'ppMat') ||
this.assets.createMaterial('ppMat', { color: MRE.Color3.Green() });
const ppMesh = this.assets.materials.find(m => m.name === 'ppMesh') ||
this.assets.createBoxMesh('ppMesh', 0.7, 0.3, 0.1);

this.playPauseButton = MRE.Actor.Create(this.context, {
actor: {
Expand Down Expand Up @@ -363,7 +347,7 @@ export class App {
if (this.activeTest === null) {
this.runTest(user);
} else {
this.stopTest().catch(() => { });
this.stopTest().catch(err => MRE.log.error('app', err));
}
});

Expand Down
2 changes: 1 addition & 1 deletion packages/functional-tests/src/utils/destroyActors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function destroyActors(actors: Actor | Actor[]): Actor[] {
actors = [actors];
}
for (const actor of actors) {
actor.destroy();
actor?.destroy();
}
return [];
}