Skip to content

Commit

Permalink
Use polling + timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
bavulapati committed Feb 16, 2022
1 parent 1d01d22 commit 220f582
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions spec-main/chromium-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { promisify } from 'util';
import { ifit, ifdescribe, delay, defer } from './spec-helpers';
import { AddressInfo } from 'net';
import { PipeTransport } from './pipe-transport';
const promisifiedTimers = require('timers/promises');

const features = process._linkedBinding('electron_common_features');

Expand Down Expand Up @@ -374,10 +373,15 @@ ifdescribe(process.platform === 'linux')('subprocesses', () => {
}
});

it('does not propagate GDK_BACKEND', async () => {
it('does not propagate GDK_BACKEND', async (done) => {
const appPath = path.join(fixturesPath, 'api', 'gdk-backend-check');
before(() => {
ChildProcess.execFileSync(path.join(appPath, 'before-test.sh'), { cwd: appPath, encoding: 'utf8' });
}
after(() => {
ChildProcess.execFileSync(path.join(appPath, 'after-test.sh'), { cwd: appPath, encoding: 'utf8' });
}

ChildProcess.execFileSync(path.join(appPath, 'before-test.sh'), { cwd: appPath, encoding: 'utf8' });
appProcess = ChildProcess.spawn(process.execPath, [path.join(appPath, 'main.js')], { env: { ...process.env, GDK_BACKEND: '' } });

let output = '';
Expand All @@ -390,22 +394,31 @@ ifdescribe(process.platform === 'linux')('subprocesses', () => {
throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
}

await promisifiedTimers.setTimeout(1000);

let gdkBackend = fs.readFileSync('/tmp/groot-says', 'utf8');
gdkBackend = gdkBackend.trim();
let waitTime = 0, timeToWait = 5000, intervalTime = 5;
const intervalId = setInterval(() => {
waitTime += intervalTime;
if (fs.existsSync('/tmp/groot-says')) {
let gdkBackend = fs.readFileSync('/tmp/groot-says', 'utf8');
gdkBackend = gdkBackend.trim();

expect(gdkBackend).to.be.empty();

ChildProcess.execFileSync(path.join(appPath, 'after-test.sh'), { cwd: appPath, encoding: 'utf8' });
expect(gdkBackend).to.be.empty();
done();
}
if (waitTime >= timeToWait) {
throw new Error("The gdk backend test failed timing out on waiting for the file");
clearInterval(intervalId);
}
}, 5);
});

it('successfully honors GDK_BACKEND set in the subproc', async () => {
const appPath = path.join(fixturesPath, 'api', 'gdk-backend-check');

console.log('gdk_backend before shell open', process.env.GDK_BACKEND);

ChildProcess.execFileSync(path.join(appPath, 'before-test.sh'), { cwd: appPath, encoding: 'utf8' });
before(() => {
ChildProcess.execFileSync(path.join(appPath, 'before-test.sh'), { cwd: appPath, encoding: 'utf8' });
}
after(() => {
ChildProcess.execFileSync(path.join(appPath, 'after-test.sh'), { cwd: appPath, encoding: 'utf8' });
}

appProcess = ChildProcess.spawn(process.execPath, [path.join(appPath, 'main.js')], { env: { ...process.env, GDK_BACKEND: 'groot' } });

Expand All @@ -419,16 +432,22 @@ ifdescribe(process.platform === 'linux')('subprocesses', () => {
throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
}

await promisifiedTimers.setTimeout(1000);
let waitTime = 0, timeToWait = 5000, intervalTime = 5;
const intervalId = setInterval(() => {
waitTime += intervalTime;
if (fs.existsSync('/tmp/groot-says')) {
let gdkBackend = fs.readFileSync('/tmp/groot-says', 'utf8');
gdkBackend = gdkBackend.trim();

let gdkBackend = fs.readFileSync('/tmp/groot-says', 'utf8');
gdkBackend = gdkBackend.trim();

console.log('gdkBackend ', gdkBackend);
expect(gdkBackend).to.not.be.empty();
expect(gdkBackend).to.equal('groot');

ChildProcess.execFileSync(path.join(appPath, 'after-test.sh'), { cwd: appPath, encoding: 'utf8' });
expect(gdkBackend).to.not.be.empty();
expect(gdkBackend).to.equal('groot');
done();
}
if (waitTime >= timeToWait) {
throw new Error("The gdk backend test failed timing out on waiting for the file");
clearInterval(intervalId);
}
}, 5);
});
});

Expand Down

0 comments on commit 220f582

Please sign in to comment.