Skip to content

Commit 4011b9a

Browse files
test: fix flaky sample test (#732)
Co-authored-by: Alex <7764119+AVaksman@users.noreply.github.com>
1 parent 3959753 commit 4011b9a

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

handwritten/datastore/samples/concepts.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ let datastore = {
3939
save: makeStub(),
4040
};
4141

42+
const namespace = `${Date.now()}`;
4243
class TestHelper {
4344
constructor(projectId) {
4445
const options = {
4546
projectId: projectId,
47+
namespace,
4648
};
4749
this.datastore = new Datastore(options);
4850
}
@@ -53,6 +55,7 @@ class Entity extends TestHelper {
5355
super(projectId);
5456
// To create the keys, we have to use this instance of Datastore.
5557
datastore.key = this.datastore.key;
58+
datastore.namespace = this.datastore.namespace;
5659

5760
this.incompleteKey = this.getIncompleteKey();
5861
this.namedKey = this.getNamedKey();

handwritten/datastore/samples/test/concepts.test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,19 @@ describe('concepts', () => {
4343

4444
after(async () => {
4545
const datastore = transaction.datastore;
46-
const query = datastore.createQuery('Task').select('__key__');
46+
const query = datastore.createQuery('__kind__').select('__key__');
4747
const [entities] = await datastore.runQuery(query);
48-
await datastore.delete(entities.map(entity => entity[datastore.KEY]));
48+
const testKinds = entities.map(entity => entity[datastore.KEY].name);
49+
50+
async function deleteEntities(kind) {
51+
const query = datastore.createQuery(kind).select('__key__');
52+
const [entities] = await datastore.runQuery(query);
53+
const keys = entities.map(entity => {
54+
return entity[datastore.KEY];
55+
});
56+
await datastore.delete(keys);
57+
}
58+
await Promise.all(testKinds.map(kind => deleteEntities(kind)));
4959
});
5060

5161
// Transactions

0 commit comments

Comments
 (0)