Change configure Jupyter server steps from async to sync (#13937)

* change config steps to sync

* fix tests

* use pathexistsSync

* remove pathExistsSync call

* address PR comments
This commit is contained in:
Lucy Zhang
2021-01-20 15:45:54 -08:00
committed by GitHub
parent 58d4dda1e8
commit 068649cba4
5 changed files with 29 additions and 33 deletions
@@ -28,10 +28,10 @@ describe('Utils Tests', function () {
should(utils.getLivyUrl(host, port)).endWith('/gateway/default/livy/v1/');
});
it('mkDir', async () => {
it('ensureDir', async () => {
const dirPath = path.join(os.tmpdir(), uuid.v4());
await should(fs.stat(dirPath)).be.rejected();
await utils.mkDir(dirPath, new MockOutputChannel());
await utils.ensureDir(dirPath, new MockOutputChannel());
should.exist(await fs.stat(dirPath), `Folder ${dirPath} did not exist after creation`);
});
@@ -55,17 +55,15 @@ describe('Jupyter server instance', function (): void {
it('Should create config and data directories on configure', async function (): Promise<void> {
// Given a server instance
let mkdirStub = sinon.stub(utils,'mkDir').withArgs(sinon.match.any,sinon.match.any).returns(Promise.resolve());
let copyStub = sinon.stub(fs,'copy').returns();
let pathStub = sinon.stub(utils,'exists').withArgs(sinon.match.any).returns(Promise.resolve(false));
let ensureDirSyncStub = sinon.stub(utils,'ensureDirSync').withArgs(sinon.match.any,sinon.match.any).returns();
let copyStub = sinon.stub(fs,'copySync').returns();
// When I run configure
await serverInstance.configure();
// Then I expect a folder to have been created with config and data subdirs
sinon.assert.callCount(mkdirStub,5);
sinon.assert.callCount(ensureDirSyncStub,5);
sinon.assert.callCount(copyStub,3);
sinon.assert.callCount(pathStub,1);
});
it('Should have URI info after start', async function (): Promise<void> {
@@ -152,8 +150,8 @@ describe('Jupyter server instance', function (): void {
it('Should remove directory on close', async function (): Promise<void> {
// Given configure and startup are done
sinon.stub(utils,'mkDir').withArgs(sinon.match.any,sinon.match.any).returns(Promise.resolve());
sinon.stub(fs,'copy').returns();
sinon.stub(utils,'ensureDirSync').withArgs(sinon.match.any,sinon.match.any).returns();
sinon.stub(fs,'copySync').returns();
let process = setupSpawn({
sdtout: (listener: (msg: string) => void) => { },