Skip to content

Commit

Permalink
chore: add pushing and installation profiling logic (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
umutuzgur committed Aug 5, 2019
1 parent 211d17d commit 4421c0b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/ios-deploy.js
Expand Up @@ -3,10 +3,12 @@ import { fs } from 'appium-support';
import path from 'path';
import { services } from 'appium-ios-device';
import B from 'bluebird';
import log from './logger';

const APPLICATION_INSTALLED_NOTIFICATION = 'com.apple.mobile.application_installed';
const INSTALLATION_STAGING_DIR = 'PublicStaging';
const APPLICATION_PUSH_TIMEOUT = 60 * 1000;
const APPLICATION_NOTIFICATION_TIMEOUT = 30 * 1000;

class IOSDeploy {

Expand All @@ -28,30 +30,37 @@ class IOSDeploy {
}

async install (app) {
const start = new Date();
try {
const bundlePathOnPhone = await this.pushAppBundle(app);
await this.installApplcation(bundlePathOnPhone);
await this.installApplication(bundlePathOnPhone);
log.info(`Installation is successful after ${new Date() - start}ms`);
} catch (err) {
throw new Error(`Could not install app: '${err.message}'`);
}
}

async installApplcation (bundlePathOnPhone) {
async installApplication (bundlePathOnPhone) {
const notificationService = await services.startNotificationProxyService(this.udid);
const installationService = await services.startInstallationProxyService(this.udid);
const appInstalledNotification = new B((resolve) => {
notificationService.observeNotification(APPLICATION_INSTALLED_NOTIFICATION, { notification: resolve });
});
}).timeout(APPLICATION_NOTIFICATION_TIMEOUT);
try {
await installationService.installApplication(bundlePathOnPhone, { PackageType: 'Developer'});
await appInstalledNotification;
try {
await appInstalledNotification;
} catch (e) {
log.warn(`Couldn't get the application installed notification with ${APPLICATION_INSTALLED_NOTIFICATION}ms but we will continue`);
}
} finally {
installationService.close();
notificationService.close();
}
}

async pushAppBundle (app) {
const start = new Date();
const afcService = await services.startAfcService(this.udid);
try {
const bundlePathOnPhone = await this.createAppPath(afcService, app);
Expand All @@ -67,7 +76,12 @@ class IOSDeploy {
readStream.pipe(writeStream);
}
});
await B.all(promises).timeout(APPLICATION_PUSH_TIMEOUT);
try {
await B.all(promises).timeout(APPLICATION_PUSH_TIMEOUT);
} catch (e) {
throw new Error(`Couldn't push all the files within the timeout ${APPLICATION_INSTALLED_NOTIFICATION}ms`);
}
log.debug(`Pushed the app files successfully after ${new Date() - start}ms`);
return bundlePathOnPhone;
} finally {
afcService.close();
Expand Down

0 comments on commit 4421c0b

Please sign in to comment.