Skip to content

Commit

Permalink
fix: add sleep after admin request intensive tests (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
asthamohta authored Dec 16, 2022
1 parent 0a394df commit 7643ceb
Showing 1 changed file with 24 additions and 49 deletions.
73 changes: 24 additions & 49 deletions system-test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1816,100 +1816,78 @@ describe('Spanner', () => {
});

describe('FineGrainedAccessControl', () => {
const createUserDefinedDatabaseRole = (done, database, query) => {
const createUserDefinedDatabaseRole = async (database, query) => {
database.updateSchema(
[query],
execAfterOperationComplete(err => {
assert.ifError(err);
database.getSchema((err, statements) => {
assert.ifError(err);
assert.ok(statements.includes(query));
done();
});
})
);
};

it('GOOGLE_STANDARD_SQL should create a user defined role', function (done) {
it('GOOGLE_STANDARD_SQL should create a user defined role', async function () {
if (IS_EMULATOR_ENABLED) {
this.skip();
}
createUserDefinedDatabaseRole(done, DATABASE, 'CREATE ROLE parent');
await createUserDefinedDatabaseRole(DATABASE, 'CREATE ROLE parent');
await new Promise(resolve => setTimeout(resolve, 60000));
});

const grantAccessToRole = (
done,
const grantAccessToRole = async (
database,
createRoleQuery,
grantAccessQuery
) => {
database.updateSchema(
[createRoleQuery],
[createRoleQuery, grantAccessQuery],
execAfterOperationComplete(err => {
assert.ifError(err);
database.getSchema((err, statements) => {
assert.ifError(err);
assert.ok(statements.includes(createRoleQuery));
database.updateSchema(
[grantAccessQuery],
execAfterOperationComplete(err => {
assert.ifError(err);
database.getSchema((err, statements) => {
assert.ifError(err);
assert.ok(statements.includes(grantAccessQuery));
done();
});
})
);
assert.ok(statements.includes(grantAccessQuery));
});
})
);
};

it('GOOGLE_STANDARD_SQL should grant access to a user defined role', function (done) {
it('GOOGLE_STANDARD_SQL should grant access to a user defined role', async function () {
if (IS_EMULATOR_ENABLED) {
this.skip();
}
grantAccessToRole(
done,
await grantAccessToRole(
DATABASE,
'CREATE ROLE child',
'GRANT SELECT ON TABLE Singers TO ROLE child'
);
await new Promise(resolve => setTimeout(resolve, 60000));
});

const userDefinedDatabaseRoleRevoked = (
done,
const userDefinedDatabaseRoleRevoked = async (
database,
createRoleQuery,
grantPermissionQuery,
revokePermissionQuery
) => {
database.updateSchema(
[createRoleQuery],
[createRoleQuery, grantPermissionQuery],
execAfterOperationComplete(err => {
assert.ifError(err);
database.getSchema((err, statements) => {
assert.ifError(err);
assert.ok(statements.includes(createRoleQuery));
assert.ok(statements.includes(grantPermissionQuery));
database.updateSchema(
[grantPermissionQuery],
[revokePermissionQuery],
execAfterOperationComplete(err => {
assert.ifError(err);
database.getSchema((err, statements) => {
assert.ifError(err);
assert.ok(statements.includes(grantPermissionQuery));
database.updateSchema(
[revokePermissionQuery],
execAfterOperationComplete(err => {
assert.ifError(err);
database.getSchema((err, statements) => {
assert.ifError(err);
assert.ok(!statements.includes(grantPermissionQuery));
done();
});
})
);
assert.ok(!statements.includes(grantPermissionQuery));
});
})
);
Expand All @@ -1918,21 +1896,20 @@ describe('Spanner', () => {
);
};

it('GOOGLE_STANDARD_SQL should revoke permissions of a user defined role', function (done) {
it('GOOGLE_STANDARD_SQL should revoke permissions of a user defined role', async function () {
if (IS_EMULATOR_ENABLED) {
this.skip();
}
userDefinedDatabaseRoleRevoked(
done,
await userDefinedDatabaseRoleRevoked(
DATABASE,
'CREATE ROLE orphan',
'GRANT SELECT ON TABLE Singers TO ROLE orphan',
'REVOKE SELECT ON TABLE Singers FROM ROLE orphan'
);
await new Promise(resolve => setTimeout(resolve, 60000));
});

const userDefinedDatabaseRoleDropped = (
done,
const userDefinedDatabaseRoleDropped = async (
database,
createRoleQuery,
dropRoleQuery
Expand All @@ -1951,7 +1928,6 @@ describe('Spanner', () => {
database.getSchema((err, statements) => {
assert.ifError(err);
assert.ok(!statements.includes(createRoleQuery));
done();
});
})
);
Expand All @@ -1960,16 +1936,16 @@ describe('Spanner', () => {
);
};

it('GOOGLE_STANDARD_SQL should drop the user defined role', function (done) {
it('GOOGLE_STANDARD_SQL should drop the user defined role', async function () {
if (IS_EMULATOR_ENABLED) {
this.skip();
}
userDefinedDatabaseRoleDropped(
done,
await userDefinedDatabaseRoleDropped(
DATABASE,
'CREATE ROLE new_parent',
'DROP ROLE new_parent'
);
await new Promise(resolve => setTimeout(resolve, 60000));
});

const grantAccessSuccess = (done, database) => {
Expand Down Expand Up @@ -2121,14 +2097,14 @@ describe('Spanner', () => {
});
};

it('GOOGLE_STANDARD_SQL should get IAM Policy', async function () {
it('GOOGLE_STANDARD_SQL should set IAM Policy', async function () {
if (IS_EMULATOR_ENABLED) {
this.skip();
}
await setIamPolicy(DATABASE);
});

it('POSTGRESQL should should get IAM Policy', async function () {
it('POSTGRESQL should should set IAM Policy', async function () {
if (IS_EMULATOR_ENABLED) {
this.skip();
}
Expand Down Expand Up @@ -6969,7 +6945,6 @@ describe('Spanner', () => {

const partitionedUpdate = (done, database, query) => {
database.runPartitionedUpdate(query, err => {
console.log('batch partition error ' + err);
assert.match(
err.details,
/THEN RETURN is not supported in Partitioned DML\./
Expand Down

0 comments on commit 7643ceb

Please sign in to comment.