Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 48 additions & 41 deletions system-test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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()));
});
});

Expand Down
Loading