diff --git a/system-test/spanner.ts b/system-test/spanner.ts index 750ea0231..09996119a 100644 --- a/system-test/spanner.ts +++ b/system-test/spanner.ts @@ -215,23 +215,6 @@ describe('Spanner', () => { await pg_database.updateSchema(schema); await postgreSqlOperationUpdateDDL.promise(); RESOURCES_TO_CLEAN.push(PG_DATABASE); - - // Create a user-managed instance config from a base instance config. - const [baseInstanceConfig] = await spanner.getInstanceConfig( - INSTANCE_CONFIG.config - ); - const customInstanceConfigRequest = { - replicas: baseInstanceConfig.replicas!.concat( - baseInstanceConfig!.optionalReplicas![0] - ), - baseConfig: baseInstanceConfig.name, - gaxOptions: GAX_OPTIONS, - }; - const [, operation] = await instanceConfig.create( - customInstanceConfigRequest - ); - await operation.promise(); - INSTANCE_CONFIGS_TO_CLEAN.push(instanceConfig); } }); @@ -272,15 +255,6 @@ describe('Spanner', () => { } catch (err) { console.error('Cleanup failed:', err); } - /** - * Deleting instance configs created during this test. - * @see {@link https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig} - */ - await Promise.all( - INSTANCE_CONFIGS_TO_CLEAN.map(instanceConfig => - instanceConfig.delete({gaxOpts: GAX_OPTIONS}) - ) - ); }); describe('Autogenerated Admin Client', async () => { @@ -2187,6 +2161,39 @@ describe('Spanner', () => { }); describe('instanceConfigs', () => { + before(async () => { + if (!IS_EMULATOR_ENABLED) { + // Create a user-managed instance config from a base instance config. + const [baseInstanceConfig] = await spanner.getInstanceConfig( + INSTANCE_CONFIG.config + ); + const customInstanceConfigRequest = { + replicas: baseInstanceConfig.replicas!.concat( + baseInstanceConfig!.optionalReplicas![0] + ), + baseConfig: baseInstanceConfig.name, + gaxOptions: GAX_OPTIONS, + }; + const [, operation] = await instanceConfig.create( + customInstanceConfigRequest + ); + await operation.promise(); + INSTANCE_CONFIGS_TO_CLEAN.push(instanceConfig); + } + }); + + after(async () => { + /** + * Deleting instance configs created during this test. + * @see {@link https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig} + */ + await Promise.all( + INSTANCE_CONFIGS_TO_CLEAN.map(instanceConfig => + instanceConfig.delete({gaxOpts: GAX_OPTIONS}) + ) + ); + }); + it('should have created the instance config', function (done) { if (IS_EMULATOR_ENABLED) { this.skip(); @@ -3952,13 +3959,13 @@ describe('Spanner', () => { const [sessions] = await dbNewRole.batchCreateSessions({count}); assert.strictEqual(sessions.length, count); - sessions.forEach(session => - session.getMetadata((err, metadata) => { - assert.ifError(err); - assert.strictEqual('parent_role', metadata?.databaseRole); + await Promise.all( + sessions.map(async session => { + const metadata = await session.getMetadata(); + assert.strictEqual('parent_role', metadata[0].databaseRole); + await session.delete(); }) ); - await Promise.all(sessions.map(session => session.delete())); }); it('should batch create sessions with database role by overriding session database-role', async function () { @@ -3972,13 +3979,13 @@ describe('Spanner', () => { }); assert.strictEqual(sessions.length, count); - sessions.forEach(session => - session.getMetadata((err, metadata) => { - assert.ifError(err); - assert.strictEqual('child_role', metadata?.databaseRole); + await Promise.all( + sessions.map(async session => { + const metadata = await session.getMetadata(); + assert.strictEqual('child_role', metadata[0].databaseRole); + await session.delete(); }) ); - await Promise.all(sessions.map(session => session.delete())); }); it('should batch create sessions with database role by overriding database-role', async function () { @@ -3992,13 +3999,13 @@ describe('Spanner', () => { }); assert.strictEqual(sessions.length, count); - sessions.forEach(session => - session.getMetadata((err, metadata) => { - assert.ifError(err); - assert.strictEqual('orphan_role', metadata?.databaseRole); + await Promise.all( + sessions.map(async session => { + const metadata = await session.getMetadata(); + assert.strictEqual('orphan_role', metadata[0].databaseRole); + await session.delete(); }) ); - await Promise.all(sessions.map(session => session.delete())); }); });