Skip to content
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
2 changes: 1 addition & 1 deletion src/addon-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ export class AddonManager extends EventEmitter {

// Load the add-on
console.log(`Loading add-on: ${manifest.id}`);
this.pluginServer!.loadPlugin(addonPath, <string>manifest.id, <string>manifest.exec);
await this.pluginServer!.loadPlugin(addonPath, <string>manifest.id, <string>manifest.exec);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/adapter-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export default class AdapterProxy extends Adapter {
*/
unload(): Promise<void> {
if (this.unloadCompletedPromise) {
console.error('AdapterProxy: unload already in progress');
return Promise.reject();
console.warn('AdapterProxy: unload already in progress');
return this.unloadCompletedPromise.getPromise();
}
this.unloadCompletedPromise = new Deferred();
this.sendMsg(MessageType.ADAPTER_UNLOAD_REQUEST, {
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/plugin-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ export default class PluginServer extends EventEmitter {
*
* Loads a plugin by launching a separate process.
*/
loadPlugin(pluginPath: string, id: string, exec: string): void {
loadPlugin(pluginPath: string, id: string, exec: string): Promise<void> {
const plugin = this.registerPlugin(id);
plugin.setExec(exec);
plugin.setExecPath(pluginPath);
plugin.start();
return plugin.start();
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export default class Plugin {

private stderrReadline?: readline.Interface;

private unloding = false;

constructor(
private pluginId: string,
private addonManager: AddonManager,
Expand Down Expand Up @@ -323,6 +325,10 @@ export default class Plugin {
switch (msg.messageType) {
case MessageType.ADAPTER_ADDED_NOTIFICATION: {
const data = msg.data as AdapterAddedNotificationMessageData;
if (this.unloding) {
console.warn('Adapter', data.adapterId, 'added during unloading');
return;
}
const adapter = new AdapterProxy(
this.addonManager,
data.adapterId,
Expand Down Expand Up @@ -861,7 +867,9 @@ export default class Plugin {
}

unload(): void {
console.log('Unloading plugin', this.pluginId);
this.restart = false;
this.unloding = true;
this.sendMsg(MessageType.PLUGIN_UNLOAD_REQUEST, {});
}

Expand Down
22 changes: 17 additions & 5 deletions src/test/browser/load-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { waitForExpect } from '../expect-utils';
import { getBrowser } from './browser-common';
import AddonManager from '../../addon-manager';

const DEFAULT_CLICKABLE_TIMEOUT = 5000;
describe('basic browser tests', () => {
afterEach(async () => {
try {
Expand All @@ -29,10 +30,11 @@ describe('basic browser tests', () => {
await confirmPassword.setValue('rosebud');

const createUserButton = await browser.$('#create-user-button');
await createUserButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await createUserButton.click();

const menuButton = await browser.$('#menu-button');
await menuButton.waitForExist({ timeout: 5000 });
await menuButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });

await waitForExpect(async () => {
const newUrl = await browser.getUrl();
Expand All @@ -53,8 +55,8 @@ describe('basic browser tests', () => {
}

await menuButton.click();

const settingsMenuItem = await browser.$('#settings-menu-item');
await settingsMenuItem.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await settingsMenuItem.click();

// wait fadeout menu-scrim
Expand All @@ -76,27 +78,31 @@ describe('basic browser tests', () => {
);

const addonSettingsLink = await browser.$('#addon-settings-link');
await addonSettingsLink.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await addonSettingsLink.click();

const discoverAddonsButton = await browser.$('#discover-addons-button');
await discoverAddonsButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await discoverAddonsButton.click();

const addonInstallVirtualThingsAdapter = await browser.$(
'#addon-install-virtual-things-adapter'
);
await addonInstallVirtualThingsAdapter.waitForExist({ timeout: 5000 });
await addonInstallVirtualThingsAdapter.waitForClickable({ timeout: 10000 });
await addonInstallVirtualThingsAdapter.click();

// virtual-things-adapter is ~10MB, so it might take some time to install
const addonDiscoverySettingsAdded = await browser.$('.addon-discovery-settings-added');
await addonDiscoverySettingsAdded.waitForExist({ timeout: 30000 });

const settingsBackButton = await browser.$('#settings-back-button');
await settingsBackButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await settingsBackButton.click();
await settingsBackButton.click();
await menuButton.click();

const thingsMenuItem = await browser.$('#things-menu-item');
await thingsMenuItem.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await thingsMenuItem.click();

// wait fadeout menu-scrim
Expand All @@ -118,7 +124,7 @@ describe('basic browser tests', () => {
);

const addButton = await browser.$('#add-button');
await addButton.waitForDisplayed({ timeout: 5000 });
await addButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await addButton.click();

const newThingVirtualThings2SaveButton = await browser.$(
Expand All @@ -127,26 +133,31 @@ describe('basic browser tests', () => {
const newThingVirtualThings9SaveButton = await browser.$(
'#new-thing-virtual-things-9 > .new-thing-save-button'
);
await newThingVirtualThings2SaveButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await newThingVirtualThings9SaveButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await newThingVirtualThings2SaveButton.click();
await newThingVirtualThings9SaveButton.click();

const addThingBackButton = await browser.$('#add-thing-back-button');
await addThingBackButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await addThingBackButton.click();

let things: ElementArray | null = null;
await waitForExpect(async () => {
things = await browser.$$('.thing');
expect(things!.length).toBe(2);
});

await things![0].waitForDisplayed({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await things![0].click();

let link = await things![0].$('.thing-details-link');
await link.waitForClickable({ timeout: 10000 });
await link.click();
let detailUrl = await browser.getUrl();
expect(detailUrl.endsWith('/things/virtual-things-2')).toBeTruthy();

const backButton = await browser.$('#back-button');
await backButton.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await backButton.click();

const webthingCustomCapability = await browser.$('webthing-custom-capability');
Expand All @@ -155,6 +166,7 @@ describe('basic browser tests', () => {
things = await browser.$$('.thing');
expect(things!.length).toBe(2);
link = await things![1].$('.thing-details-link');
await link.waitForClickable({ timeout: DEFAULT_CLICKABLE_TIMEOUT });
await link.click();
detailUrl = await browser.getUrl();
expect(detailUrl.endsWith('/things/virtual-things-9')).toBeTruthy();
Expand Down
1 change: 1 addition & 0 deletions src/test/browser/page-object/settings-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SettingSection extends Section {
const el = this.rootElement!;
const href = await el.getAttribute('href');
const id = await el.getAttribute('id');
await el.waitForClickable();
await el.click();

switch (id) {
Expand Down
14 changes: 14 additions & 0 deletions src/test/browser/things-view/thing-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForThings();
Expand Down Expand Up @@ -130,6 +131,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForThings();
Expand Down Expand Up @@ -189,6 +191,8 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForThings();
Expand Down Expand Up @@ -262,6 +266,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForOffThings();
Expand Down Expand Up @@ -302,6 +307,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForOffThings();
Expand Down Expand Up @@ -349,6 +355,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForOffThings();
Expand Down Expand Up @@ -441,6 +448,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForOffThings();
Expand Down Expand Up @@ -522,6 +530,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForOffThings();
Expand Down Expand Up @@ -622,6 +631,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForOffThings();
Expand Down Expand Up @@ -739,6 +749,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForOffThings();
Expand Down Expand Up @@ -870,6 +881,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForOffThings();
Expand Down Expand Up @@ -913,6 +925,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForThings();
Expand Down Expand Up @@ -952,6 +965,7 @@ describe('Thing', () => {
await addThing(desc);

const thingsPage = new ThingsPage(browser);
await thingsPage.wait();
await thingsPage.open();

await thingsPage.waitForThings();
Expand Down
8 changes: 7 additions & 1 deletion src/test/integration/internal-logs-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ describe('internal-logs/', () => {
beforeEach(async () => {
jwt = await createUser(server, TEST_USER);
fs.writeFileSync(path.join(UserProfile.logDir, 'test.log'), 'hello, world!');

// clean up folder from previous logs
const regex = /^run-app\.log\./;
fs.readdirSync(UserProfile.logDir)
.filter((f) => regex.test(f))
.map((f) => fs.unlinkSync(path.join(UserProfile.logDir, f)));
});

it('GET internal-logs index', async () => {
Expand Down Expand Up @@ -55,7 +61,7 @@ describe('internal-logs/', () => {
});
expect(res.status).toEqual(200);
expect(res.type).toBe('application/zip');
expect(Object.keys(res.body.files).length).toEqual(2);
expect(Object.keys(res.body.files).length).toEqual(1);
const file = res.body.file('logs/test.log');
expect(file).toBeTruthy();
const data = await file.async('text');
Expand Down