Skip to content

Commit 84d07a1

Browse files
tgriessermjhenkesestrada9166emilyrohrbough
authored
chore: add batch execution to CloudDataSource (#22457)
Co-authored-by: Matt Henkes <mjhenkes@gmail.com> Co-authored-by: estrada9166 <estrada9166@gmail.com> Co-authored-by: Emily Rohrbough <emilyrohrbough@yahoo.com> Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
1 parent f1f2c73 commit 84d07a1

File tree

9 files changed

+329
-116
lines changed

9 files changed

+329
-116
lines changed

packages/app/cypress/e2e/specs_list_flaky.cy.ts

+38-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,18 @@ describe('App: Spec List - Flaky Indicator', () => {
3535
dashboardUrl: '#',
3636
},
3737
}
38-
} else {
39-
obj.result.data.cloudSpecByPath = {
38+
}
39+
}
40+
41+
return obj.result
42+
})
43+
44+
cy.remoteGraphQLInterceptBatched(async (obj) => {
45+
await new Promise((r) => setTimeout(r, 20))
46+
47+
if (obj.field === 'cloudSpecByPath') {
48+
if (obj.variables.specPath.includes('123.spec.js')) {
49+
return {
4050
__typename: 'CloudProjectSpec',
4151
id: `id${obj.variables.specPath}`,
4252
retrievedAt: new Date().toISOString(),
@@ -45,12 +55,34 @@ describe('App: Spec List - Flaky Indicator', () => {
4555
__typename: 'CloudSpecRunConnection',
4656
nodes: [],
4757
},
48-
isConsideredFlaky: false,
49-
flakyStatus: null,
58+
isConsideredFlaky: true,
59+
flakyStatus: {
60+
__typename: 'CloudProjectSpecFlakyStatus',
61+
severity: 'LOW',
62+
flakyRuns: 2,
63+
flakyRunsWindow: 50,
64+
lastFlaky: 2,
65+
dashboardUrl: '#',
66+
},
5067
}
5168
}
52-
} else if (obj.result.data && 'cloudLatestRunUpdateSpecData' in obj.result.data) {
53-
obj.result.data.cloudLatestRunUpdateSpecData = {
69+
70+
return {
71+
__typename: 'CloudProjectSpec',
72+
id: `id${obj.variables.specPath}`,
73+
retrievedAt: new Date().toISOString(),
74+
averageDuration: null,
75+
specRuns: {
76+
__typename: 'CloudSpecRunConnection',
77+
nodes: [],
78+
},
79+
isConsideredFlaky: false,
80+
flakyStatus: null,
81+
}
82+
}
83+
84+
if (obj.field === 'cloudLatestRunUpdateSpecData') {
85+
return {
5486
__typename: 'CloudLatestRunUpdateSpecData',
5587
mostRecentUpdate: new Date('2022-06-10').toISOString(),
5688
pollingInterval: 60,

packages/app/cypress/e2e/specs_list_latest_runs.cy.ts

+110-102
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ function specShouldShow (specFileName: string, runDotsClasses: string[], latestR
6666
}
6767

6868
function simulateRunData () {
69-
cy.remoteGraphQLIntercept(async (obj) => {
69+
cy.remoteGraphQLInterceptBatched(async (obj) => {
70+
if (obj.field !== 'cloudSpecByPath') {
71+
return obj.result
72+
}
73+
7074
const fakeRuns = (statuses: string[], idPrefix: string) => {
7175
return statuses.map((s, idx) => {
7276
return {
@@ -107,34 +111,30 @@ function simulateRunData () {
107111
})
108112
}
109113

110-
if (obj.result.data && 'cloudSpecByPath' in obj.result.data) {
111-
// simulate network latency to allow for caching to register
112-
await new Promise((r) => setTimeout(r, 20))
113-
114-
const statuses = obj.variables.specPath?.includes('accounts_list.spec.js') ?
115-
['PASSED', 'FAILED', 'CANCELLED', 'ERRORED'] :
116-
obj.variables.specPath?.includes('app.spec.js') ?
117-
[] :
118-
['RUNNING', 'PASSED']
119-
120-
const runs = fakeRuns(statuses, obj.variables.specPath)
121-
const averageDuration = obj.variables.specPath?.includes('accounts_list.spec.js') ?
122-
12000 : // 0:12
123-
123000 // 2:03
124-
125-
obj.result.data.cloudSpecByPath = {
126-
__typename: 'CloudProjectSpec',
127-
retrievedAt: new Date().toISOString(),
128-
id: `id${obj.variables.specPath}`,
129-
specRuns: {
130-
__typename: 'CloudSpecRunConnection',
131-
nodes: runs,
132-
},
133-
averageDuration,
134-
}
114+
// simulate network latency to allow for caching to register
115+
await new Promise((r) => setTimeout(r, 20))
116+
117+
const statuses = obj.variables.specPath?.includes('accounts_list.spec.js') ?
118+
['PASSED', 'FAILED', 'CANCELLED', 'ERRORED'] :
119+
obj.variables.specPath?.includes('app.spec.js') ?
120+
[] :
121+
['RUNNING', 'PASSED']
122+
123+
const runs = fakeRuns(statuses, obj.variables.specPath)
124+
const averageDuration = obj.variables.specPath?.includes('accounts_list.spec.js') ?
125+
12000 : // 0:12
126+
123000 // 2:03
127+
128+
return {
129+
__typename: 'CloudProjectSpec',
130+
retrievedAt: new Date().toISOString(),
131+
id: `id${obj.variables.specPath}`,
132+
specRuns: {
133+
__typename: 'CloudSpecRunConnection',
134+
nodes: runs,
135+
},
136+
averageDuration,
135137
}
136-
137-
return obj.result
138138
})
139139
}
140140

@@ -163,21 +163,12 @@ describe('App/Cloud Integration - Latest runs and Average duration', { viewportW
163163
it('shows placeholders for all visible specs', { defaultCommandTimeout: 6000 }, () => {
164164
cy.loginUser()
165165

166-
cy.remoteGraphQLIntercept(async (obj) => {
167-
if (obj.result.data && 'cloudSpecByPath' in obj.result.data) {
168-
obj.result.data.cloudSpecByPath = {
169-
__typename: 'CloudProjectSpecNotFound',
170-
retrievedAt: new Date().toISOString(),
171-
id: `id${obj.variables.specPath}`,
172-
specRuns: {
173-
__typename: 'CloudSpecRunConnection',
174-
nodes: [],
175-
},
176-
averageDuration: null,
177-
}
166+
cy.remoteGraphQLInterceptBatched(async (obj) => {
167+
return {
168+
__typename: 'CloudProjectSpecNotFound',
169+
retrievedAt: new Date().toISOString(),
170+
message: 'Spec Not Found',
178171
}
179-
180-
return obj.result
181172
})
182173

183174
cy.visitApp()
@@ -350,6 +341,7 @@ describe('App/Cloud Integration - Latest runs and Average duration', { viewportW
350341
cy.get('.v-popper__popper--shown').should('not.exist')
351342
cy.get(dotSelector('app.spec.js', 'latest')).trigger('mouseleave')
352343

344+
cy.get('.spec-list-container').scrollTo('top')
353345
// oldest 2 status dots will use placeholder
354346
specShouldShow('accounts_new.spec.js', ['gray-300', 'gray-300', 'jade-400'], 'RUNNING')
355347
cy.get(dotSelector('accounts_new.spec.js', 'latest')).trigger('mouseenter')
@@ -436,6 +428,30 @@ describe('App/Cloud Integration - Latest runs and Average duration', { viewportW
436428
cy.loginUser()
437429

438430
cy.remoteGraphQLIntercept(async (obj, testState) => {
431+
const pollingCounter = testState.pollingCounter ?? 0
432+
433+
if (obj.result.data && 'cloudLatestRunUpdateSpecData' in obj.result.data) {
434+
const mostRecentUpdate = pollingCounter > 1 ? new Date().toISOString() : new Date('2022-06-10').toISOString()
435+
// initial polling interval is set to every second to avoid long wait times
436+
const pollingInterval = pollingCounter > 1 ? 30 : 1
437+
438+
obj.result.data.cloudLatestRunUpdateSpecData = {
439+
__typename: 'CloudLatestRunUpdateSpecData',
440+
mostRecentUpdate,
441+
pollingInterval,
442+
}
443+
444+
testState.pollingCounter = pollingCounter + 1
445+
}
446+
447+
return obj.result
448+
})
449+
450+
cy.remoteGraphQLInterceptBatched(async (obj, testState) => {
451+
if (obj.field !== 'cloudSpecByPath') {
452+
return obj.result
453+
}
454+
439455
const fakeRuns = (statuses: string[], idPrefix: string) => {
440456
return statuses.map((s, idx) => {
441457
return {
@@ -478,39 +494,23 @@ describe('App/Cloud Integration - Latest runs and Average duration', { viewportW
478494

479495
const pollingCounter = testState.pollingCounter ?? 0
480496

481-
if (obj.result.data && 'cloudSpecByPath' in obj.result.data) {
482-
// simulate network latency to allow for caching to register
483-
await new Promise((r) => setTimeout(r, 20))
484-
485-
const statuses = pollingCounter < 2 ? ['PASSED', 'FAILED', 'CANCELLED', 'ERRORED'] : ['FAILED', 'PASSED', 'FAILED', 'CANCELLED', 'ERRORED']
486-
const runs = fakeRuns(statuses, obj.variables.specPath)
487-
const averageDuration = pollingCounter < 2 ? 12000 : 13000
488-
489-
obj.result.data.cloudSpecByPath = {
490-
__typename: 'CloudProjectSpec',
491-
retrievedAt: new Date().toISOString(),
492-
id: `id${obj.variables.specPath}`,
493-
specRuns: {
494-
__typename: 'CloudSpecRunConnection',
495-
nodes: runs,
496-
},
497-
averageDuration,
498-
}
499-
} else if (obj.result.data && 'cloudLatestRunUpdateSpecData' in obj.result.data) {
500-
const mostRecentUpdate = pollingCounter > 1 ? new Date().toISOString() : new Date('2022-06-10').toISOString()
501-
// initial polling interval is set to every second to avoid long wait times
502-
const pollingInterval = pollingCounter > 1 ? 30 : 1
497+
// simulate network latency to allow for caching to register
498+
await new Promise((r) => setTimeout(r, 20))
503499

504-
obj.result.data.cloudLatestRunUpdateSpecData = {
505-
__typename: 'CloudLatestRunUpdateSpecData',
506-
mostRecentUpdate,
507-
pollingInterval,
508-
}
500+
const statuses = pollingCounter < 2 ? ['PASSED', 'FAILED', 'CANCELLED', 'ERRORED'] : ['FAILED', 'PASSED', 'FAILED', 'CANCELLED', 'ERRORED']
501+
const runs = fakeRuns(statuses, obj.variables.specPath)
502+
const averageDuration = pollingCounter < 2 ? 12000 : 13000
509503

510-
testState.pollingCounter = pollingCounter + 1
504+
return {
505+
__typename: 'CloudProjectSpec',
506+
retrievedAt: new Date().toISOString(),
507+
id: `id${obj.variables.specPath}`,
508+
specRuns: {
509+
__typename: 'CloudSpecRunConnection',
510+
nodes: runs,
511+
},
512+
averageDuration,
511513
}
512-
513-
return obj.result
514514
})
515515

516516
cy.visitApp()
@@ -542,6 +542,30 @@ describe('App/Cloud Integration - Latest runs and Average duration', { viewportW
542542
cy.loginUser()
543543

544544
cy.remoteGraphQLIntercept(async (obj, testState) => {
545+
const pollingCounter = testState.pollingCounter ?? 0
546+
547+
if (obj.result.data && 'cloudLatestRunUpdateSpecData' in obj.result.data) {
548+
const mostRecentUpdate = new Date('2022-06-10').toISOString()
549+
// initial polling interval is set to every second to avoid long wait times
550+
const pollingInterval = pollingCounter > 1 ? 30 : 1
551+
552+
obj.result.data.cloudLatestRunUpdateSpecData = {
553+
__typename: 'CloudLatestRunUpdateSpecData',
554+
mostRecentUpdate,
555+
pollingInterval,
556+
}
557+
558+
testState.pollingCounter = pollingCounter + 1
559+
}
560+
561+
return obj.result
562+
})
563+
564+
cy.remoteGraphQLInterceptBatched(async (obj, testState) => {
565+
if (obj.field !== 'cloudSpecByPath') {
566+
return obj.result
567+
}
568+
545569
const fakeRuns = (statuses: string[], idPrefix: string) => {
546570
return statuses.map((s, idx) => {
547571
return {
@@ -584,39 +608,23 @@ describe('App/Cloud Integration - Latest runs and Average duration', { viewportW
584608

585609
const pollingCounter = testState.pollingCounter ?? 0
586610

587-
if (obj.result.data && 'cloudSpecByPath' in obj.result.data) {
588-
// simulate network latency to allow for caching to register
589-
await new Promise((r) => setTimeout(r, 20))
590-
591-
const statuses = pollingCounter < 2 ? ['PASSED', 'FAILED', 'CANCELLED', 'ERRORED'] : ['FAILED', 'PASSED', 'FAILED', 'CANCELLED', 'ERRORED']
592-
const runs = fakeRuns(statuses, obj.variables.specPath)
593-
const averageDuration = pollingCounter < 2 ? 12000 : 13000
594-
595-
obj.result.data.cloudSpecByPath = {
596-
__typename: 'CloudProjectSpec',
597-
retrievedAt: new Date().toISOString(),
598-
id: `id${obj.variables.specPath}`,
599-
specRuns: {
600-
__typename: 'CloudSpecRunConnection',
601-
nodes: runs,
602-
},
603-
averageDuration,
604-
}
605-
} else if (obj.result.data && 'cloudLatestRunUpdateSpecData' in obj.result.data) {
606-
const mostRecentUpdate = new Date('2022-06-10').toISOString()
607-
// initial polling interval is set to every second to avoid long wait times
608-
const pollingInterval = pollingCounter > 1 ? 30 : 1
611+
// simulate network latency to allow for caching to register
612+
await new Promise((r) => setTimeout(r, 20))
609613

610-
obj.result.data.cloudLatestRunUpdateSpecData = {
611-
__typename: 'CloudLatestRunUpdateSpecData',
612-
mostRecentUpdate,
613-
pollingInterval,
614-
}
614+
const statuses = pollingCounter < 2 ? ['PASSED', 'FAILED', 'CANCELLED', 'ERRORED'] : ['FAILED', 'PASSED', 'FAILED', 'CANCELLED', 'ERRORED']
615+
const runs = fakeRuns(statuses, obj.variables.specPath)
616+
const averageDuration = pollingCounter < 2 ? 12000 : 13000
615617

616-
testState.pollingCounter = pollingCounter + 1
618+
return {
619+
__typename: 'CloudProjectSpec',
620+
retrievedAt: new Date().toISOString(),
621+
id: `id${obj.variables.specPath}`,
622+
specRuns: {
623+
__typename: 'CloudSpecRunConnection',
624+
nodes: runs,
625+
},
626+
averageDuration,
617627
}
618-
619-
return obj.result
620628
})
621629

622630
cy.visitApp()

0 commit comments

Comments
 (0)