Skip to content

Commit d297a64

Browse files
committed
test: add delay to system tests for search indexing
Introduced a 30-second delay after test product creation using timers/promises. This allows the Google Cloud Retail search indexes enough time to build, preventing flaky test failures caused by eventual consistency.
1 parent 153b4b7 commit d297a64

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

retail/snippets/searchPagination.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function searchPagination(projectId, placementId, visitorId, query) {
4949
branch: branchPath,
5050
visitorId: visitorId,
5151
query: query,
52-
pageSize: 5,
52+
pageSize: 1,
5353
};
5454

5555
try {
@@ -74,7 +74,7 @@ async function searchPagination(projectId, placementId, visitorId, query) {
7474
branch: branchPath,
7575
visitorId: visitorId,
7676
query: query,
77-
pageSize: 5,
77+
pageSize: 1,
7878
pageToken: nextPageToken,
7979
};
8080

retail/snippets/test/snippets.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {ProductServiceClient} = require('@google-cloud/retail');
1919
const {searchOffset} = require('../searchOffset');
2020
const {searchPagination} = require('../searchPagination');
2121
const {searchRequest} = require('../searchRequest');
22+
const {setTimeout} = require('timers/promises');
2223

2324
describe('Snippets System Tests', function () {
2425
this.timeout(180000);
@@ -66,6 +67,8 @@ describe('Snippets System Tests', function () {
6667
product: product,
6768
productId: productId,
6869
});
70+
console.log('Waiting 30 seconds for search indexes to be created...');
71+
await setTimeout(30000);
6972
});
7073

7174
after(async () => {
@@ -108,6 +111,7 @@ describe('Snippets System Tests', function () {
108111

109112
const output = consoleOutput.join('\n');
110113
assert.include(output, `--- Results for offset: ${offset} ---`);
114+
assert.include(output, `Product ID: ${productId}`);
111115
});
112116

113117
it('should execute searchPagination and handle pages', async () => {
@@ -116,6 +120,7 @@ describe('Snippets System Tests', function () {
116120
const output = consoleOutput.join('\n');
117121

118122
assert.include(output, '--- First Page ---');
123+
assert.include(output, '--- Second Page ---');
119124
});
120125

121126
it('should execute searchRequest successfully', async () => {
@@ -131,5 +136,6 @@ describe('Snippets System Tests', function () {
131136

132137
const output = consoleOutput.join('\n');
133138
assert.include(output, '--- Search Results ---');
139+
assert.include(output, `Product ID: ${productId}`);
134140
});
135141
});

0 commit comments

Comments
 (0)