Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(instance): update stats after user resets an instance #492

Merged
merged 1 commit into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/api/src/datasources/instances.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Collection } from '@sorry-cypress/mongo';
import { DataSource } from 'apollo-datasource';
import { findIndex } from 'lodash';
import { RunSpec } from '../generated/graphql';

export class InstancesAPI extends DataSource {
getInstanceById(instanceId: string) {
Expand Down Expand Up @@ -48,19 +50,29 @@ export class InstancesAPI extends DataSource {
};
}

let runSpec: RunSpec | null;
run.specs = run.specs.map((spec) => {
if (spec.instanceId === instanceId) {
runSpec = spec;
return {
...spec,
claimedAt: null,
completedAt: null,
machineId: undefined,
results: undefined,
};
} else {
return spec;
}
});

const groupId = instance.groupId;
const groupIndex = findIndex(run.progress.groups, { groupId });
const groupPath = `progress.groups.${groupIndex}`;
const stats = runSpec!.results?.stats;
const retries = runSpec!.results?.retries;
const specFailed = stats?.failures && stats.failures > 0;

await Collection.run().updateOne(
{
runId: run.runId,
Expand All @@ -72,6 +84,18 @@ export class InstancesAPI extends DataSource {
completed: false,
},
},
$inc: {
[`${groupPath}.instances.claimed`]: -1,
[`${groupPath}.instances.complete`]: -1,
[`${groupPath}.instances.passes`]: -(specFailed ? 0 : 1),
[`${groupPath}.instances.failures`]: -(specFailed ? 1 : 0),
[`${groupPath}.tests.overall`]: -(stats?.tests || 0),
[`${groupPath}.tests.passes`]: -(stats?.passes || 0),
[`${groupPath}.tests.failures`]: -(stats?.failures || 0),
[`${groupPath}.tests.skipped`]: -(stats?.skipped || 0),
[`${groupPath}.tests.pending`]: -(stats?.pending || 0),
[`${groupPath}.tests.retries`]: -(retries || 0),
},
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useResetInstanceMutation,
} from '@sorry-cypress/dashboard/generated/graphql';
import { useAsync } from '@sorry-cypress/dashboard/hooks/';
import { client } from '@sorry-cypress/dashboard/lib/apolloClient';
import { getBase } from '@sorry-cypress/dashboard/lib/path';
import React, { useCallback, useEffect, useState } from 'react';

Expand Down Expand Up @@ -56,6 +57,7 @@ export const ResetInstanceButton = ({
if (!deleteResult) {
return;
}
client.reFetchObservableQueries();
setShowModal(false);
}, [deleteResult]);

Expand Down