Skip to content

Commit

Permalink
Added fromBranch param to averageDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
MuazOthman committed Jun 9, 2022
1 parent 5c95239 commit 1489d14
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 41 deletions.
7 changes: 4 additions & 3 deletions packages/app/src/specs/AverageDuration.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div
v-if="props.gql?.avgDurationInfo?.status === 'FETCHED' && props.gql?.avgDurationInfo.data?.__typename === 'CloudProjectSpec' && props.gql?.avgDurationInfo?.data?.averageDuration"
v-if="props.gql?.avgDurationInfo?.fetchingStatus === 'FETCHED' && props.gql?.avgDurationInfo.data?.__typename === 'CloudProjectSpec' && props.gql?.avgDurationInfo?.data?.averageDuration"
class="h-full grid text-gray-700 justify-end items-center"
data-cy="average-duration"
>
Expand Down Expand Up @@ -42,7 +42,8 @@ fragment AverageDuration on Spec {
data {
... on CloudProjectSpec {
id
averageDuration
averageDuration(fromBranch: $fromBranch)
retrievedAt
}
}
}
Expand All @@ -61,7 +62,7 @@ const props = withDefaults(defineProps<{
watchEffect(
() => {
if (props.isOnline && (props.gql?.avgDurationInfo?.status === 'NOT_FETCHED' || props.gql?.avgDurationInfo?.status === undefined)) {
if (props.isOnline && (props.gql?.avgDurationInfo?.fetchingStatus === 'NOT_FETCHED' || props.gql?.avgDurationInfo?.fetchingStatus === undefined)) {
refetch()
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/specs/SpecsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const isGitAvailable = computed(() => {
})
const hasCloudErrors = computed(() => {
return props.gql.currentProject?.specs.some((s) => s.cloudSpec?.status === 'ERRORED' || s.avgDurationInfo?.status === 'ERRORED') ?? false
return props.gql.currentProject?.specs.some((s) => s.cloudSpec?.fetchingStatus === 'ERRORED' || s.avgDurationInfo?.fetchingStatus === 'ERRORED') ?? false
})
const shouldShowFetchError = ref(false)
Expand Down Expand Up @@ -404,11 +404,11 @@ const refetchMutation = useMutation(CloudData_RefetchDocument)
function refetchFailedCloudData () {
const latestRunsIds = props.gql.currentProject?.specs
.filter((s) => s.cloudSpec?.status === 'ERRORED')
.filter((s) => s.cloudSpec?.fetchingStatus === 'ERRORED')
.map((s) => s.cloudSpec?.id as string) ?? []
const avgInfoIds = props.gql.currentProject?.specs
.filter((s) => s.avgDurationInfo?.status === 'ERRORED')
.filter((s) => s.avgDurationInfo?.fetchingStatus === 'ERRORED')
.map((s) => s.avgDurationInfo?.id as string) ?? []
refetchMutation.executeMutation({ ids: [...avgInfoIds, ...latestRunsIds] })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class RemotePollingDataSource {
requestPolicy: 'network-only', // we never want to hit local cache for this request
})

debug(`Response for startPollingForSpecs %o`, result)
debug(`%s Response for startPollingForSpecs %o`, new Date().toISOString(), result)

const secondsToPollNext = (result.data?.cloudLatestRunUpdateSpecData?.pollingInterval ?? 30)
const mostRecentUpdate = result.data?.cloudLatestRunUpdateSpecData?.mostRecentUpdate ?? null
Expand Down
90 changes: 70 additions & 20 deletions packages/graphql/schemas/cloud.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
Represents a pollable status for clients to know when refetching data is required.
"""
type CloudLatestRunUpdateSpecData {
"""
DateTime of the latest update in a project.
"""
mostRecentUpdate: DateTime

"""
Recommended seconds to wait before next poll.
"""
pollingInterval: Int
}

Expand Down Expand Up @@ -195,7 +202,15 @@ union CloudProjectResult =
| CloudProjectUnauthorized

type CloudProjectSpec implements Node {
averageDuration: Float
"""
Average duration the spec takes to run
"""
averageDuration(
"""
The branch to measure average duration against. This will fallback to the closest branch with data.
"""
fromBranch: String!
): Float

"""
Globally unique identifier representing a concrete GraphQL ObjectType
Expand All @@ -207,8 +222,20 @@ type CloudProjectSpec implements Node {
"""
fromBranch: String!
): Boolean

"""
Current DateTime on the server. Used in connection with CloudLatestRunUpdateSpecData.
"""
retrievedAt: DateTime

"""
Shortened spec path
"""
specPath: String

"""
Runs this spec has been involved with.
"""
specRuns(
"""
Returns the elements in the list that come after the specified cursor
Expand All @@ -226,7 +253,7 @@ type CloudProjectSpec implements Node {
first: Int

"""
The branch to filter on for the specs
The branch to filter on for the specs. This will fallback to the closest branch with data.
"""
fromBranch: String!

Expand Down Expand Up @@ -417,21 +444,59 @@ type CloudRunTag implements Node {
A Recorded run of a given spec from the Test Runner, typically to the cloud
"""
type CloudSpecRun implements Node {
"""
When the run was completed
"""
completedAt: DateTime

"""
When the run was created
"""
createdAt: DateTime

"""
Amount of groups this spec was run in
"""
groupCount: Int

"""
Globally unique identifier representing a concrete GraphQL ObjectType
"""
id: ID!
retrievalDateTime: DateTime

"""
Incremental run number assigned
"""
runNumber: Int

"""
Aggregate information about how long the spec took to run in the groups
"""
specDuration: SpecDataAggregate

"""
Most important status for the spec shared between all groups
"""
status: CloudRunStatus

"""
Aggregate information about how many tests failed in the groups
"""
testsFailed: SpecDataAggregate

"""
Aggregate information about how many tests passed in the groups
"""
testsPassed: SpecDataAggregate

"""
Aggregate information about how many tests are pending in the groups
"""
testsPending: SpecDataAggregate

"""
Aggregate information about how many tests were skipped in the groups
"""
testsSkipped: SpecDataAggregate

"""
Expand Down Expand Up @@ -599,11 +664,11 @@ type PageInfo {

type Query {
"""
Poll this query to determine when it's required to refresh run data for a given spec or branch. Returns the recommended time until next fetch. A 0 value means data is available.
Polling query to determine when to refetch spec data. A null value here means no data available in the cloud.
"""
cloudLatestRunUpdateSpecData(
"""
Clients active branch to search for builds
Clients active branch to search for builds. This will fallback to the closest branch with data.
"""
commitBranch: String!

Expand Down Expand Up @@ -668,21 +733,6 @@ type Query {
specPath: String!
): CloudProjectSpecResult

"""
Gets a set of specs on a given project and branch
"""
cloudSpecsByPath(
"""
Slug of the project to which the set of specs belong
"""
projectSlug: String!

"""
A set of specs to include identified by spec path
"""
specPaths: [String!]!
): [CloudProjectSpec]

"""
A user within the Cypress Cloud
"""
Expand Down
60 changes: 46 additions & 14 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ type CachedUser implements Node {
Represents a pollable status for clients to know when refetching data is required.
"""
type CloudLatestRunUpdateSpecData {
"""DateTime of the latest update in a project."""
mostRecentUpdate: DateTime

"""Recommended seconds to wait before next poll."""
pollingInterval: Int
}

Expand Down Expand Up @@ -198,16 +201,30 @@ type CloudProjectNotFound {
union CloudProjectResult = CloudProject | CloudProjectNotFound | CloudProjectUnauthorized

type CloudProjectSpec implements Node {
averageDuration: Float
"""Average duration the spec takes to run"""
averageDuration(
"""
The branch to measure average duration against. This will fallback to the closest branch with data.
"""
fromBranch: String!
): Float

"""Globally unique identifier representing a concrete GraphQL ObjectType"""
id: ID!
isConsideredFlaky(
"""The branch to measure flakiness against"""
fromBranch: String!
): Boolean

"""
Current DateTime on the server. Used in connection with CloudLatestRunUpdateSpecData.
"""
retrievedAt: DateTime

"""Shortened spec path"""
specPath: String

"""Runs this spec has been involved with."""
specRuns(
"""Returns the elements in the list that come after the specified cursor"""
after: String
Expand All @@ -218,7 +235,9 @@ type CloudProjectSpec implements Node {
"""Returns the first n elements from the list."""
first: Int

"""The branch to filter on for the specs"""
"""
The branch to filter on for the specs. This will fallback to the closest branch with data.
"""
fromBranch: String!

"""Returns the last n elements from the list."""
Expand Down Expand Up @@ -357,19 +376,39 @@ type CloudRunTag implements Node {
A Recorded run of a given spec from the Test Runner, typically to the cloud
"""
type CloudSpecRun implements Node {
"""When the run was completed"""
completedAt: DateTime

"""When the run was created"""
createdAt: DateTime

"""Amount of groups this spec was run in"""
groupCount: Int

"""Globally unique identifier representing a concrete GraphQL ObjectType"""
id: ID!
retrievalDateTime: DateTime

"""Incremental run number assigned"""
runNumber: Int

"""
Aggregate information about how long the spec took to run in the groups
"""
specDuration: SpecDataAggregate

"""Most important status for the spec shared between all groups"""
status: CloudRunStatus

"""Aggregate information about how many tests failed in the groups"""
testsFailed: SpecDataAggregate

"""Aggregate information about how many tests passed in the groups"""
testsPassed: SpecDataAggregate

"""Aggregate information about how many tests are pending in the groups"""
testsPending: SpecDataAggregate

"""Aggregate information about how many tests were skipped in the groups"""
testsSkipped: SpecDataAggregate

"""A link to the run overview page filtered by spec"""
Expand Down Expand Up @@ -1322,10 +1361,12 @@ type Query {
cachedUser: CachedUser

"""
Poll this query to determine when it's required to refresh run data for a given spec or branch. Returns the recommended time until next fetch. A 0 value means data is available.
Polling query to determine when to refetch spec data. A null value here means no data available in the cloud.
"""
cloudLatestRunUpdateSpecData(
"""Clients active branch to search for builds"""
"""
Clients active branch to search for builds. This will fallback to the closest branch with data.
"""
commitBranch: String!

"""A list of Project slugs"""
Expand Down Expand Up @@ -1365,15 +1406,6 @@ type Query {
specPath: String!
): CloudProjectSpecResult

"""Gets a set of specs on a given project and branch"""
cloudSpecsByPath(
"""Slug of the project to which the set of specs belong"""
projectSlug: String!

"""A set of specs to include identified by spec path"""
specPaths: [String!]!
): [CloudProjectSpec]

"""A user within the Cypress Cloud"""
cloudViewer: CloudUser

Expand Down
2 changes: 2 additions & 0 deletions packages/graphql/src/schemaTypes/objectTypes/gql-Spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const Spec = objectType({
shouldEagerFetch: () => false, // defaults to false to be fully lazy and rely on the UI to fetch as needed
queryArgs: async (source, args, ctx) => {
const projectId = await ctx.project.projectId()
const fromBranch = ctx.lifecycleManager.git?.currentBranch

if (!projectId) {
return false
Expand All @@ -62,6 +63,7 @@ export const Spec = objectType({
return {
projectSlug: projectId,
specPath: source.relative,
fromBranch,
}
},
})
Expand Down

0 comments on commit 1489d14

Please sign in to comment.