@@ -22,6 +22,26 @@ const {describe, it, before, after} = require('mocha');
22
22
const talent = require ( '@google-cloud/talent' ) . v4 ;
23
23
const execSync = cmd => cp . execSync ( cmd , { encoding : 'utf-8' } ) ;
24
24
25
+ /**
26
+ * For eventually consistent APIs, retry the test after a few seconds, up to 3 times.
27
+ * @param {function } testFunction the test function to retry.
28
+ * @returns {function }
29
+ */
30
+ function eventually ( testFunction ) {
31
+ return async ( ) => {
32
+ let delayMs = 2000 ;
33
+ for ( let i = 0 ; i < 2 ; ++ i ) {
34
+ try {
35
+ return await testFunction ( ) ;
36
+ } catch ( e ) {
37
+ await new Promise ( resolve => setTimeout ( resolve , delayMs ) ) ;
38
+ delayMs *= 2 ;
39
+ }
40
+ }
41
+ return await testFunction ( ) ;
42
+ } ;
43
+ }
44
+
25
45
describe ( 'Talent Solution Jobs API v4 samples' , ( ) => {
26
46
const projectId = process . env . GCLOUD_PROJECT ;
27
47
const tenantService = new talent . TenantServiceClient ( ) ;
@@ -118,23 +138,29 @@ describe('Talent Solution Jobs API v4 samples', () => {
118
138
assert . match ( output , new RegExp ( 'Name' ) ) ;
119
139
} ) ;
120
140
121
- it ( 'Searches for a job with custom ranking search' , async ( ) => {
122
- console . log (
123
- `node snippet/job_search_custom_ranking_search.js --project_id=${ projectId } --tenant_id=${ tenantId } `
124
- ) ;
125
- const output = execSync (
126
- `node snippet/job_search_custom_ranking_search.js --project_id=${ projectId } --tenant_id=${ tenantId } `
127
- ) ;
128
- assert . match ( output , new RegExp ( 'Job summary' ) ) ;
129
- } ) ;
130
-
131
- it ( 'Searches for a job with histogram' , async ( ) => {
132
- console . log (
133
- `node snippet/job_search_histogram_search.js --project_id=${ projectId } --tenant_id=${ tenantId } `
134
- ) ;
135
- const output = execSync (
136
- `node snippet/job_search_histogram_search.js --project_id=${ projectId } --tenant_id=${ tenantId } `
137
- ) ;
138
- assert . match ( output , new RegExp ( 'Job summary' ) ) ;
139
- } ) ;
141
+ it (
142
+ 'Searches for a job with custom ranking search' ,
143
+ eventually ( async ( ) => {
144
+ console . log (
145
+ `node snippet/job_search_custom_ranking_search.js --project_id=${ projectId } --tenant_id=${ tenantId } `
146
+ ) ;
147
+ const output = execSync (
148
+ `node snippet/job_search_custom_ranking_search.js --project_id=${ projectId } --tenant_id=${ tenantId } `
149
+ ) ;
150
+ assert . match ( output , new RegExp ( 'Job summary' ) ) ;
151
+ } )
152
+ ) ;
153
+
154
+ it (
155
+ 'Searches for a job with histogram' ,
156
+ eventually ( async ( ) => {
157
+ console . log (
158
+ `node snippet/job_search_histogram_search.js --project_id=${ projectId } --tenant_id=${ tenantId } `
159
+ ) ;
160
+ const output = execSync (
161
+ `node snippet/job_search_histogram_search.js --project_id=${ projectId } --tenant_id=${ tenantId } `
162
+ ) ;
163
+ assert . match ( output , new RegExp ( 'Job summary' ) ) ;
164
+ } )
165
+ ) ;
140
166
} ) ;
0 commit comments