Skip to content

Commit

Permalink
fix(Android): pass headless config param to the AVD validator. (#3614)
Browse files Browse the repository at this point in the history
This is a bug-fix to address the `headless` config when running tests (invoked as `emulator -version`) by the AVD emulator version validator. Resolves #3613
  • Loading branch information
paulrostorp authored and noomorph committed Oct 3, 2022
1 parent bd5998c commit 28469d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class AVDValidator {
this._emulatorVersionResolver = emulatorVersionResolver;
}

async validate(avdName) {
async validate(avdName, isHeadless) {
const avds = await this._avdsResolver.resolve(avdName);
this._assertAVDs(avds);
await this._assertAVDMatch(avds, avdName);
await this._validateEmulatorVer();
await this._validateEmulatorVer(isHeadless);
}

_assertAVDs(avds) {
Expand All @@ -37,8 +37,8 @@ class AVDValidator {
}
}

async _validateEmulatorVer() {
const emulatorVersion = await this._emulatorVersionResolver.resolve();
async _validateEmulatorVer(isHeadless) {
const emulatorVersion = await this._emulatorVersionResolver.resolve(isHeadless);
if (!emulatorVersion) {
logger.warn({ event: 'AVD_VALIDATION' }, 'Emulator version detection failed (See previous logs)');
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,13 @@ describe('AVD validator', () => {
'Emulator version detection failed (See previous logs)'
);
});

it('should run emulator version resolver as headless if required', async () => {
givenExpectedAVD();
givenProperEmulatorVersion();

await uut.validate('mock-avd-name', true);

expect(versionResolver.resolve).toHaveBeenCalledWith(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EmulatorAllocDriver extends AllocationDriverBase {
async allocate(deviceConfig) {
const avdName = deviceConfig.device.avdName;

await this._avdValidator.validate(avdName);
await this._avdValidator.validate(avdName, deviceConfig.headless);
await this._fixAvdConfigIniSkinNameIfNeeded(avdName, deviceConfig.headless);

const allocResult = await this._allocationHelper.allocateDevice(avdName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ describe('Allocation driver for Google emulators', () => {
it('should pre-validate proper AVD configuration', async () => {
givenValidAVD();
await allocDriver.allocate(deviceConfig);
expect(avdValidator.validate).toHaveBeenCalledWith(avdName);
expect(avdValidator.validate).toHaveBeenCalledWith(avdName, undefined);
});

it('should respect headless avd configuration during AVD validation', async () => {
givenValidAVD();
await allocDriver.allocate({ ...deviceConfig, headless: true });
expect(avdValidator.validate).toHaveBeenCalledWith(avdName, true);
});

it('should throw if AVD configuration is invalid', async () => {
Expand Down

0 comments on commit 28469d4

Please sign in to comment.