Skip to content

Commit f1cc072

Browse files
authored
fix(aggregations): use maxTimeMS default on preview docs COMPASS-7798 (#5972)
1 parent 1035cb1 commit f1cc072

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

packages/compass-aggregations/src/modules/input-documents.spec.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
import { expect } from 'chai';
2+
import { defaultPreferencesInstance } from 'compass-preferences-model';
3+
import sinon from 'sinon';
4+
15
import reducer, {
26
toggleInputDocumentsCollapsed,
37
updateInputDocuments,
48
loadingInputDocuments,
9+
refreshInputDocuments,
510
ActionTypes,
611
} from './input-documents';
7-
import { expect } from 'chai';
12+
import type { RootState } from '.';
13+
import type { DataService } from './data-service';
814

915
describe('input documents module', function () {
16+
afterEach(function () {
17+
sinon.restore();
18+
});
19+
1020
describe('#toggleInputDocumentsCollapsed', function () {
1121
it('returns the ActionTypes.CollapseToggled action', function () {
1222
expect(toggleInputDocumentsCollapsed()).to.deep.equal({
@@ -33,6 +43,53 @@ describe('input documents module', function () {
3343
});
3444
});
3545

46+
describe('#refreshInputDocuments', function () {
47+
it('should apply maxTimeMS to the aggregation when it is set', async function () {
48+
const refreshInputDocumentsThunk = refreshInputDocuments();
49+
50+
const mockAggregate = sinon.stub().resolves([]);
51+
const mockState: Partial<RootState> = {
52+
dataService: {
53+
dataService: {
54+
aggregate: mockAggregate,
55+
} as unknown as DataService,
56+
},
57+
namespace: 'test.namespace',
58+
maxTimeMS: undefined,
59+
settings: {
60+
isExpanded: false,
61+
isCommentMode: false,
62+
isDirty: false,
63+
limit: 10,
64+
sampleSize: 10,
65+
},
66+
};
67+
68+
await refreshInputDocumentsThunk(
69+
sinon.stub(),
70+
() => mockState as RootState,
71+
{ preferences: defaultPreferencesInstance } as any
72+
);
73+
74+
expect(mockAggregate.calledOnce).to.be.true;
75+
expect(mockAggregate.firstCall.args[2]).to.deep.equal({
76+
maxTimeMS: 60_000,
77+
});
78+
79+
mockState.maxTimeMS = 1000;
80+
await refreshInputDocumentsThunk(
81+
sinon.stub(),
82+
() => mockState as RootState,
83+
{ preferences: defaultPreferencesInstance } as any
84+
);
85+
86+
expect(mockAggregate.calledTwice).to.be.true;
87+
expect(mockAggregate.secondCall.args[2]).to.deep.equal({
88+
maxTimeMS: 1000,
89+
});
90+
});
91+
});
92+
3693
describe('#reducer', function () {
3794
context(
3895
'when the action is not toggle input documents collapsed',

packages/compass-aggregations/src/modules/input-documents.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model/provide
33
import type { PipelineBuilderThunkAction } from '.';
44
import type { AnyAction } from 'redux';
55
import { isAction } from '../utils/is-action';
6+
import { DEFAULT_MAX_TIME_MS } from '../constants';
67

78
export enum ActionTypes {
89
CollapseToggled = 'aggregations/input-documents/CollapseToggled',
@@ -111,9 +112,10 @@ export const refreshInputDocuments = (): PipelineBuilderThunkAction<
111112
}
112113

113114
const options = {
114-
maxTimeMS: capMaxTimeMSAtPreferenceLimit(preferences, maxTimeMS) as
115-
| number
116-
| undefined,
115+
maxTimeMS: capMaxTimeMSAtPreferenceLimit(
116+
preferences,
117+
maxTimeMS ?? DEFAULT_MAX_TIME_MS
118+
),
117119
};
118120

119121
const aggregateOptions = { ...options };

0 commit comments

Comments
 (0)