Skip to content

Commit

Permalink
test: Move obtain test instance (#1225)
Browse files Browse the repository at this point in the history
* Move obtainTestInstance into the before block for

backups

* Extend expiry time

* Revert "Extend expiry time"

This reverts commit 8d42852.

* Revert "Move obtainTestInstance into the before block for"

This reverts commit 3eb0d8f.

* Add comment for backups

* Add comments to functions file

* Move obtainTestInstance in write module

* Fix reads sample tests

* Comment adjustment
  • Loading branch information
danieljbruce committed Jan 30, 2023
1 parent 0822e4d commit 9e1ab05
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions samples/test/backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe('backups', async () => {
const TABLE_ID = generateId();
const BACKUP_ID = generateId();

// The following `obtainTestInstance` line needs to be moved into `before`.
// This needs to happen when we get the backup tests running again.
const instance = await obtainTestInstance();

const INSTANCE_ID = instance.id;
Expand Down
2 changes: 2 additions & 0 deletions samples/test/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const cwd = path.join(__dirname, '..');
const TABLE_ID = `mobile-time-series-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules

describe('functions', async () => {
// The following `obtainTestInstance` line needs to be moved into `before`.
// This needs to happen when we get the functions tests running again.
const instance = await obtainTestInstance();
const INSTANCE_ID = instance.id;
let table;
Expand Down
11 changes: 7 additions & 4 deletions samples/test/reads.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const TABLE_ID = `mobile-time-series-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules

describe('reads', async () => {
const instance = await obtainTestInstance();
const INSTANCE_ID = instance.id;
let INSTANCE_ID;
let table;
const TIMESTAMP = new Date(2019, 5, 1);
TIMESTAMP.setUTCHours(0);

before(async () => {
const instance = await obtainTestInstance();
INSTANCE_ID = instance.id;

const TIMESTAMP = new Date(2019, 5, 1);
TIMESTAMP.setUTCHours(0);

table = instance.table(TABLE_ID);
await table.create();
await table.createFamily('stats_summary');
Expand Down
2 changes: 2 additions & 0 deletions samples/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ async function getStaleInstances() {
* the result.
*/
async function obtainTestInstance() {
// Note: This function should only be called inside a `before` or `it` block.
// Note: Otherwise it will try to create an instance more than once.
if (!obtainPromise) {
obtainPromise = createTestInstance();
}
Expand Down
6 changes: 4 additions & 2 deletions samples/test/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const TABLE_ID = `mobile-time-series-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules

describe('writes', async () => {
const instance = await obtainTestInstance();
const INSTANCE_ID = instance.id;
let INSTANCE_ID;
let table;

before(async () => {
const instance = await obtainTestInstance();
INSTANCE_ID = instance.id;

table = instance.table(TABLE_ID);

await table.create().catch(console.error);
Expand Down

0 comments on commit 9e1ab05

Please sign in to comment.