Skip to content

Commit

Permalink
Revert "config: skip reset on local config DOGU_DEVICE_SKIP_RESET_FOR…
Browse files Browse the repository at this point in the history
…_LOCAL"

This reverts commit e1d6888.
  • Loading branch information
yowpark committed Dec 15, 2023
1 parent c8701b3 commit 3b521bd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { delay, filterAsync, loop, PrefixLogger, retry, stringify } from '@dogu-
import { CheckTimer } from '@dogu-tech/node';
import semver from 'semver';
import { AppiumContextImpl } from '../../../appium/appium.context';
import { env } from '../../../env';
import { AdbSerial, AppiumAdb } from '../../externals/index';
export interface AndroidResetInfo {
lastResetTime: number;
Expand Down Expand Up @@ -59,43 +58,32 @@ export class AndroidResetService {
const { serial, logger } = this;
await retry(
async (): Promise<void> => {
logger.info(`AndroidResetService.reset begin`, { serial, info });

if (env.DOGU_RUN_TYPE === 'local' && env.DOGU_DEVICE_SKIP_RESET_FOR_LOCAL) {
logger.info(`AndroidResetService.reset skipped for local`, { serial, info });
} else {
await this.runReset(info, appiumAdb, appiumContext);
logger.info(`AndroidResetService.resetDevice begin`, { serial, info });
try {
this._state = 'resetting';
if (!this.isHarnessAvailable(info)) {
throw new Error(`AndroidResetService.resetDevice Android version must be 10 or higher. to use testharness, serial:${serial}. version:${info.version}`);
}
await this.check(`AndroidResetService.reset.enableTestharness`, this.adb.enableTestharness());
} catch (e) {
await this.check(`AndroidResetService.reset.resetAccounts`, this.resetAccounts(appiumAdb, appiumContext));
await this.check(`AndroidResetService.reset.runAppSettingsActivity`, this.adb.runActivity('android.settings.MANAGE_APPLICATIONS_SETTINGS'));
await this.check(`AndroidResetService.reset.resetSdcard`, this.adb.resetSdcard());
await this.check(`AndroidResetService.reset.resetIMEList`, this.resetIMEList());
await this.check(`AndroidResetService.reset.logcatClear`, this.adb.logcatClear());
await this.check(`AndroidResetService.reset.resetPackages`, this.adb.resetPackages());
await this.check(`AndroidResetService.reset.resetDirty`, this.resetDirty());
await this.check(`AndroidResetService.reset.reboot`, this.adb.reboot());
} finally {
this._state = null;
}

await this.check(`AndroidResetService.reset.reboot`, this.adb.reboot());
AndroidResetService.map.set(serial, { lastResetTime: Date.now() });
this.logger.info(`AndroidResetService.reset end`, { serial, info });
this.logger.info(`AndroidResetService.resetDevice end`, { serial, info });
},
{ retryCount: 5, retryInterval: 1000, printable: new PrefixLogger(logger, 'AndroidResetService.reset') },
);
}

private async runReset(info: DeviceSystemInfo, appiumAdb: AppiumAdb, appiumContext: AppiumContextImpl): Promise<void> {
const { serial } = this;
try {
this._state = 'resetting';
if (!this.isHarnessAvailable(info)) {
throw new Error(`AndroidResetService.resetDevice Android version must be 10 or higher. to use testharness, serial:${serial}. version:${info.version}`);
}
await this.check(`AndroidResetService.reset.enableTestharness`, this.adb.enableTestharness());
} catch (e) {
await this.check(`AndroidResetService.reset.resetAccounts`, this.resetAccounts(appiumAdb, appiumContext));
await this.check(`AndroidResetService.reset.runAppSettingsActivity`, this.adb.runActivity('android.settings.MANAGE_APPLICATIONS_SETTINGS'));
await this.check(`AndroidResetService.reset.resetSdcard`, this.adb.resetSdcard());
await this.check(`AndroidResetService.reset.resetIMEList`, this.resetIMEList());
await this.check(`AndroidResetService.reset.logcatClear`, this.adb.logcatClear());
await this.check(`AndroidResetService.reset.resetPackages`, this.adb.resetPackages());
await this.check(`AndroidResetService.reset.resetDirty`, this.resetDirty());
} finally {
this._state = null;
}
}

private isHarnessAvailable(systemInfo: DeviceSystemInfo): boolean {
const version = semver.coerce(systemInfo.version);
if (!version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { delay, filterAsync, loop, loopTime, PrefixLogger, Repeat, retry, TimeOp
import { CheckTimer } from '@dogu-tech/node';
import { boxBox } from 'intersects';
import { AppiumContextImpl, WDIOElement } from '../../../appium/appium.context';
import { env } from '../../../env';
import { IosDriver } from '../../driver/ios-driver';
import { IdeviceInstaller } from '../../externals/cli/ideviceinstaller';
import { WebdriverAgentProcess } from '../../externals/cli/webdriver-agent-process';
Expand Down Expand Up @@ -235,6 +234,8 @@ export class IosResetService {
if (!driver) {
throw new Error(`IosResetService.reset driver is null`);
}
const iosDriver = new IosWebDriver(driver, wda, iosWebDriverInfo, logger);
const helper = new IosResetHelper(iosDriver);

await usingAsnyc(
{
Expand All @@ -249,11 +250,22 @@ export class IosResetService {
},
},
async () => {
if (env.DOGU_RUN_TYPE === 'local' && env.DOGU_DEVICE_SKIP_RESET_FOR_LOCAL) {
logger.info(`IosResetService.reset skipped for local`, { serial });
} else {
await this.runReset(appiumContext, wda);
}
await iosDriver.homeAndDismissAlert();
await this.check('IosResetService.reset.removeSystemApps', this.removeSystemApps());
await iosDriver.homeAndDismissAlert();
await this.check('IosResetService.reset.logoutAppleAccount', this.logoutAppleAccount(iosDriver));
await this.check('IosResetService.reset.clearSafariCache', this.clearSafariCache(iosDriver));
await this.check('IosResetService.reset.clearPhotoImages', this.clearPhotoImages(iosDriver));
await this.check('IosResetService.reset.clearPhotoAlbums', this.clearPhotoAlbums(iosDriver));
await this.check('IosResetService.reset.clearPhotosRecentlyDeleted', this.clearPhotosRecentlyDeleted(iosDriver));
await this.check('IosResetService.reset.clearPhotosSuggestionAndFeedbacks', this.clearPhotosSuggestionAndFeedbacks(iosDriver));
await this.check('IosResetService.reset.clearFilesOnMyiPhone', this.clearFilesOnMyiPhone(iosDriver, helper));
await this.check('IosResetService.reset.clearFilesTags', this.clearFilesTags(iosDriver, helper));
await this.check('IosResetService.reset.clearFilesRecentlyDeleted', this.clearFilesRecentlyDeleted(iosDriver, helper));
await this.check('IosResetService.reset.resetSettings', this.resetSettings(iosDriver));
await this.check('IosResetService.reset.removeWidgets', this.removeWidgets(iosDriver));
await this.check('IosResetService.reset.clearNotifications', this.clearNotifications(iosDriver));
await this.check('IosResetService.reset.removeUserApps', this.removeUserApps()); // last step because this removes appium
await this.check(
'IosResetService.reset.restart',
retry(async (): Promise<string> => await IdeviceDiagnostics.restart(serial, logger), { retryCount: 5, retryInterval: 1000 }).catch((e) => {
Expand All @@ -269,29 +281,6 @@ export class IosResetService {
);
}

private async runReset(appiumContext: AppiumContextImpl, wda: WebdriverAgentProcess): Promise<void> {
const { serial, iosWebDriverInfo, logger } = this;
const iosDriver = new IosWebDriver(driver, wda, iosWebDriverInfo, logger);
const helper = new IosResetHelper(iosDriver);

await iosDriver.homeAndDismissAlert();
await this.check('IosResetService.reset.removeSystemApps', this.removeSystemApps());
await iosDriver.homeAndDismissAlert();
await this.check('IosResetService.reset.logoutAppleAccount', this.logoutAppleAccount(iosDriver));
await this.check('IosResetService.reset.clearSafariCache', this.clearSafariCache(iosDriver));
await this.check('IosResetService.reset.clearPhotoImages', this.clearPhotoImages(iosDriver));
await this.check('IosResetService.reset.clearPhotoAlbums', this.clearPhotoAlbums(iosDriver));
await this.check('IosResetService.reset.clearPhotosRecentlyDeleted', this.clearPhotosRecentlyDeleted(iosDriver));
await this.check('IosResetService.reset.clearPhotosSuggestionAndFeedbacks', this.clearPhotosSuggestionAndFeedbacks(iosDriver));
await this.check('IosResetService.reset.clearFilesOnMyiPhone', this.clearFilesOnMyiPhone(iosDriver, helper));
await this.check('IosResetService.reset.clearFilesTags', this.clearFilesTags(iosDriver, helper));
await this.check('IosResetService.reset.clearFilesRecentlyDeleted', this.clearFilesRecentlyDeleted(iosDriver, helper));
await this.check('IosResetService.reset.resetSettings', this.resetSettings(iosDriver));
await this.check('IosResetService.reset.removeWidgets', this.removeWidgets(iosDriver));
await this.check('IosResetService.reset.clearNotifications', this.clearNotifications(iosDriver));
await this.check('IosResetService.reset.removeUserApps', this.removeUserApps()); // last step because this removes appium
}

private async removeSystemApps(): Promise<void> {
const installer = new IdeviceInstaller(this.serial, this.logger);
const uninstallApps = BlockAppList.filter((item) => item.uninstall).map((item) => item.bundleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export class DeviceServerChild implements Child {
const DOGU_LINUX_DEVICE_SERIAL = appConfigService.getOrDefault<string>('DOGU_LINUX_DEVICE_SERIAL', '');
const DOGU_WIFI_SSID = appConfigService.getOrDefault<string>('DOGU_WIFI_SSID', '');
const DOGU_WIFI_PASSWORD = appConfigService.getOrDefault<string>('DOGU_WIFI_PASSWORD', '');
const DOGU_DEVICE_SKIP_RESET_FOR_LOCAL = appConfigService.getOrDefault<boolean>('DOGU_DEVICE_SKIP_RESET_FOR_LOCAL', false);
const DOGU_USE_SENTRY = this.featureConfigService.get('useSentry');

if (!isValidDoguRunType(DOGU_RUN_TYPE)) {
Expand Down Expand Up @@ -81,7 +80,6 @@ export class DeviceServerChild implements Child {
DOGU_WIFI_PASSWORD,
DOGU_USE_SENTRY: DOGU_USE_SENTRY ? 'true' : 'false',
DOGU_SECRET_INITIAL_ADMIN_TOKEN: this.authService.adminToken.value,
DOGU_DEVICE_SKIP_RESET_FOR_LOCAL: DOGU_DEVICE_SKIP_RESET_FOR_LOCAL ? 'true' : 'false',
},
},
childLogger: this.logger,
Expand Down
3 changes: 0 additions & 3 deletions nm-space/packages/dogu-agent-core/src/shares/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ export const AppConfigSchema = {
DOGU_WIFI_PASSWORD: {
type: 'string',
},
DOGU_DEVICE_SKIP_RESET_FOR_LOCAL: {
type: 'boolean',
},
is_show_devui: {
type: 'boolean',
},
Expand Down
4 changes: 0 additions & 4 deletions nm-space/packages/dost-children/src/envs/device-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,4 @@ export class DeviceServerEnv extends PreloadDeviceServerEnv {

@IsFilledString()
DOGU_SECRET_INITIAL_ADMIN_TOKEN = '';

@IsBoolean()
@TransformBooleanString()
DOGU_DEVICE_SKIP_RESET_FOR_LOCAL = false;
}

0 comments on commit 3b521bd

Please sign in to comment.