Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Spanner stale read sample. #475

Merged
merged 2 commits into from
Sep 14, 2017
Merged

Add Spanner stale read sample. #475

merged 2 commits into from
Sep 14, 2017

Conversation

jmdobry
Copy link
Member

@jmdobry jmdobry commented Sep 6, 2017

No description provided.

@jmdobry jmdobry self-assigned this Sep 6, 2017
@jmdobry jmdobry requested a review from ace-n September 6, 2017 15:05
@codecov
Copy link

codecov bot commented Sep 6, 2017

Codecov Report

Merging #475 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #475   +/-   ##
=======================================
  Coverage   97.16%   97.16%           
=======================================
  Files          13       13           
  Lines         458      458           
=======================================
  Hits          445      445           
  Misses         13       13

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fca8cf...e5dabb4. Read the comment docs.

spanner/crud.js Outdated
const instance = spanner.instance(instanceId);
const database = instance.database(databaseId);

// Read rows from the Albums table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: inconsistent comment tense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

spanner/crud.js Outdated
};

const options = {
// Guarantees that all writes that have committed more than 10 seconds ago
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove that have and combine into one line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

spanner/crud.js Outdated

rows.forEach((row) => {
const json = row.toJSON();
console.log(`SingerId: ${json.SingerId.value}, AlbumId: ${json.AlbumId.value}, AlbumTitle: ${json.AlbumTitle}, MarketingBudget: ${json.MarketingBudget ? json.MarketingBudget.value : ''}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we split these into separate lines? This is a lot to read at once...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

spanner/crud.js Outdated
@@ -189,10 +233,17 @@ const cli = require(`yargs`)
{},
(opts) => readData(opts.instanceName, opts.databaseName)
)
.command(
`read-stale <instanceName> <databaseName>`,
`Reads data in an example Cloud Spanner table.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: mention/explain stale reads in the command description?

e.g. Reads _stale_ data in an example Cloud Spanner table.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

const output = await tools.runAsync(`${schemaCmd} createDatabase "${INSTANCE_ID}" "${DATABASE_ID}"`, cwd);
t.true(output.includes(`Waiting for operation on ${DATABASE_ID} to complete...`));
t.true(output.includes(`Created database ${DATABASE_ID} on instance ${INSTANCE_ID}.`));
const results = await tools.runAsyncWithIO(`${schemaCmd} createDatabase "${INSTANCE_ID}" "${DATABASE_ID}"`, cwd);
Copy link
Contributor

@ace-n ace-n Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this? (Having stderr in the test printout?)

stderr should be ignored unless we expect an error to occur. (If an error occurs when it shouldn't, our test should fail - though perhaps not silently.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've discover lately that sometimes tests/commands fail silently (return a 0 exit code), but do print some useful info to stderr. This improves test debuggability.

t.true(output.includes(`Inserted data.`));
const results = await tools.runAsyncWithIO(`${crudCmd} insert ${INSTANCE_ID} ${DATABASE_ID}`, cwd);
const output = results.stdout + results.stderr;
t.regex(output, new RegExp(`Inserted data.`));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace t.regex(output, new RegExp($STRING)) with t.regex(output, /$STRING/). Apply this comment throughout your PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// read-stale-data reads data that is exactly 10 seconds old. So, make sure
// 10 seconds have elapsed since the update_data test.
return new Promise((resolve, reject) => {
setTimeout(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you promisify the setTimeout() call, and wrap the tests in a then as was done here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jmdobry
Copy link
Member Author

jmdobry commented Sep 14, 2017

Comments addressed, merging.

@jmdobry jmdobry merged commit 79dc773 into master Sep 14, 2017
@jmdobry jmdobry deleted the spanner-stale-read branch September 14, 2017 21:30
NimJay pushed a commit that referenced this pull request Nov 11, 2022
ace-n pushed a commit that referenced this pull request Nov 11, 2022
NimJay pushed a commit that referenced this pull request Nov 19, 2022
NimJay pushed a commit that referenced this pull request Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants