Skip to content

Commit

Permalink
FI-2007: Fix wait test race condition bug (#371)
Browse files Browse the repository at this point in the history
* add extra poll for wait test

* fix footer spacing

* change poll endpoint

---------

Co-authored-by: Alyssa Wang <[email protected]>
  • Loading branch information
AlyssaWang and AlyssaWang authored Jul 21, 2023
1 parent 10ae288 commit 613a964
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/src/components/Footer/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { makeStyles } from 'tss-react/mui';

export default makeStyles()((theme: Theme) => ({
footer: {
display: 'flex',
width: '100%',
overflow: 'auto',
zIndex: `${theme.zIndex.drawer + 1} !important` as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ const TestRunProgressBar: FC<TestRunProgressBarProps> = ({
}) => {
const { classes } = useStyles();
const footerHeight = useAppStore((state) => state.footerHeight);
const cancellable = testRun?.status != 'cancelling' && testRun?.status != 'done';
const cancellable = testRun?.status !== 'cancelling' && testRun?.status !== 'done';
const statusIndicator = StatusIndicator(testRun?.status);
const testCount = testRun?.test_count || 0;
const completedCount = completedTestCount(resultsMap, testRun);
const value = testCount !== 0 ? (100 * completedCount) / testCount : 0;

return (
<Snackbar
Expand Down Expand Up @@ -123,7 +122,7 @@ const TestRunProgressBar: FC<TestRunProgressBarProps> = ({
) : (
<LinearProgress
variant="determinate"
value={value}
value={(100 * completedCount) / testCount || 0}
className={classes.linearProgress}
/>
)}
Expand Down
28 changes: 25 additions & 3 deletions client/src/components/TestSuite/TestSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
isTest,
} from '~/models/testSuiteModels';
import { deleteTestRun, getTestRunWithResults, postTestRun } from '~/api/TestRunsApi';
import { getCurrentTestSessionResults } from '~/api/TestSessionApi';
import ActionModal from '~/components/_common/ActionModal';
import InputsModal from '~/components/InputsModal/InputsModal';
import TestRunProgressBar from './TestRunProgressBar/TestRunProgressBar';
Expand Down Expand Up @@ -154,7 +155,6 @@ const TestSessionComponent: FC<TestSessionComponentProps> = ({
}
});
}

setWaitingTestId(waitingTestId);
}, [resultsMap]);

Expand Down Expand Up @@ -197,8 +197,30 @@ const TestSessionComponent: FC<TestSessionComponentProps> = ({
});
});
setSessionData(new Map(sessionData));
const updatedMap = resultsToMap(testRunResults.results, resultsMap);
setResultsMap(updatedMap);

let updatedMap = resultsToMap(testRunResults.results, resultsMap);
// If wait test is causing race condition rendering bugs, fetch full results again
if (
testRunResults?.status === 'done' &&
Array.from(updatedMap.values()).some((value) => value.result === 'wait')
) {
getCurrentTestSessionResults(testSession.id)
.then((results) => {
if (results) {
updatedMap = resultsToMap(results, resultsMap);
setResultsMap(updatedMap);
} else {
enqueueSnackbar('Failed to load results', { variant: 'error' });
}
})
.catch((e: Error) => {
enqueueSnackbar(`Error while getting test results: ${e.message}`, {
variant: 'error',
});
});
} else {
setResultsMap(updatedMap);
}
}
if (testRunResults && testRunIsInProgress(testRunResults) && testSessionPolling) {
poller.current = setTimeout(() => pollTestRunResults(testRunResults), 500);
Expand Down

0 comments on commit 613a964

Please sign in to comment.