Skip to content

Commit 803a423

Browse files
authored
chore(indexes): remove in progress only when a matching index shows up in real indexes list; cleanup rolling on a timeout (#6331)
* chore(indexes): remove in progress only when a matching index shows up in real indexes list; cleanup rolling on a timeout * chore(indexes): add tests; cleanup polling on plugin deactivate
1 parent 516eced commit 803a423

File tree

9 files changed

+338
-79
lines changed

9 files changed

+338
-79
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import React from 'react';
2+
import Sinon from 'sinon';
3+
import {
4+
CompassIndexesPlugin as CompassIndexesSubtab,
5+
CompassIndexesHadronPlugin,
6+
} from './index';
7+
import {
8+
createDefaultConnectionInfo,
9+
createPluginTestHelpers,
10+
screen,
11+
userEvent,
12+
waitFor,
13+
within,
14+
} from '@mongodb-js/testing-library-compass';
15+
import { expect } from 'chai';
16+
import {
17+
indexCreationStarted,
18+
prepareInProgressIndex,
19+
rollingIndexTimeoutCheck,
20+
} from './modules/regular-indexes';
21+
22+
describe('CompassIndexesPlugin', function () {
23+
const sandbox = Sinon.createSandbox();
24+
25+
const dataService = {
26+
indexes: () => [],
27+
createIndex: () => ({}),
28+
};
29+
30+
const atlasService = {
31+
automationAgentRequest: () => ({}),
32+
automationAgentAwait: () => ({ response: [] }),
33+
authenticatedFetch: () => undefined,
34+
cloudEndpoint: () => undefined,
35+
};
36+
37+
const renderHelpers = createPluginTestHelpers(
38+
CompassIndexesHadronPlugin.withMockServices({
39+
dataService,
40+
atlasService,
41+
instance: {
42+
on: () => undefined,
43+
removeListener: () => undefined,
44+
isWritable: true,
45+
},
46+
collection: {
47+
on: () => undefined,
48+
removeListener: () => undefined,
49+
toJSON: () => ({}),
50+
},
51+
} as any)
52+
);
53+
54+
function render() {
55+
return renderHelpers.renderWithActiveConnection(
56+
<CompassIndexesSubtab.content></CompassIndexesSubtab.content>,
57+
{
58+
...createDefaultConnectionInfo(),
59+
atlasMetadata: {
60+
instanceSize: 'VERY BIG',
61+
metricsType: 'replicaSet',
62+
} as any,
63+
}
64+
);
65+
}
66+
67+
afterEach(function () {
68+
sandbox.reset();
69+
});
70+
71+
describe('rolling indexes', function () {
72+
it('should create a rolling index and show it in the table', async function () {
73+
const result = await render();
74+
75+
await waitFor(() => {
76+
expect(result.plugin.store.getState().regularIndexes).to.have.property(
77+
'status',
78+
'READY'
79+
);
80+
});
81+
82+
sandbox.stub(atlasService, 'automationAgentAwait').resolves({
83+
response: [
84+
{
85+
status: 'rolling build',
86+
indexName: 'field_a_1',
87+
indexProperties: {},
88+
indexType: { label: 'regular' },
89+
keys: [{ name: 'field_a', value: '1' }],
90+
},
91+
],
92+
});
93+
94+
/** Create rolling index */
95+
96+
userEvent.click(screen.getByRole('button', { name: 'Create Index' }));
97+
98+
userEvent.type(screen.getByLabelText('Index fields'), 'field_a');
99+
userEvent.click(screen.getByRole('option', { name: 'Field: "field_a"' }));
100+
101+
userEvent.click(screen.getByText('Select a type'));
102+
userEvent.click(screen.getByText('1 (asc)'));
103+
104+
userEvent.click(screen.getByTestId('create-index-modal-toggle-options'));
105+
106+
userEvent.click(
107+
screen.getByRole('checkbox', { name: 'Build in rolling process' }),
108+
undefined,
109+
{ skipPointerEventsCheck: true }
110+
);
111+
112+
userEvent.click(
113+
within(screen.getByTestId('create-index-modal')).getByRole('button', {
114+
name: 'Create Index',
115+
})
116+
);
117+
118+
const inProgressIndex =
119+
result.plugin.store.getState().regularIndexes.inProgressIndexes[0];
120+
121+
expect(inProgressIndex).to.exist;
122+
123+
/** Wait for the row to appear with in-progress bagde first */
124+
125+
expect(
126+
within(screen.getByTestId('indexes-row-field_a_1')).getByText(
127+
'In Progress'
128+
)
129+
).to.exist;
130+
131+
/** Now wait for the rolling index to show up */
132+
133+
await waitFor(() => {
134+
expect(
135+
within(screen.getByTestId('indexes-row-field_a_1')).getByText(
136+
'Building'
137+
)
138+
).to.exist;
139+
});
140+
141+
/** At some point rolling index timeout check fires, but nothing changes */
142+
143+
result.plugin.store.dispatch(
144+
rollingIndexTimeoutCheck(inProgressIndex.id)
145+
);
146+
147+
expect(
148+
within(screen.getByTestId('indexes-row-field_a_1')).getByText(
149+
'Building'
150+
)
151+
).to.exist;
152+
});
153+
});
154+
155+
it('should remove in progress rolling index on a timeout', async function () {
156+
const result = await render();
157+
158+
await waitFor(() => {
159+
expect(result.plugin.store.getState().regularIndexes).to.have.property(
160+
'status',
161+
'READY'
162+
);
163+
});
164+
165+
/** This time let's just do all the setup with actions directly, we tested UI above */
166+
167+
const inProgressIndex = prepareInProgressIndex('test', {
168+
name: 'test_index',
169+
spec: {},
170+
});
171+
172+
result.plugin.store.dispatch(indexCreationStarted(inProgressIndex));
173+
174+
expect(screen.getByTestId('indexes-row-test_index')).to.exist;
175+
176+
/** Timeout check "fired" before index was returned from the API, index is removed */
177+
178+
result.plugin.store.dispatch(rollingIndexTimeoutCheck('test'));
179+
180+
expect(() => screen.getByTestId('indexes-row-test_index')).to.throw();
181+
});
182+
});

packages/compass-indexes/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { telemetryLocator } from '@mongodb-js/compass-telemetry/provider';
1919
import { IndexesTabTitle } from './plugin-title';
2020
import { atlasServiceLocator } from '@mongodb-js/atlas-service/provider';
2121

22-
const CompassIndexesHadronPlugin = registerHadronPlugin(
22+
export const CompassIndexesHadronPlugin = registerHadronPlugin(
2323
{
2424
name: 'CompassIndexes',
2525
component: function IndexesProvider({ children }) {

packages/compass-indexes/src/modules/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export type IndexesExtraArgs = {
7272
connectionInfoRef: ConnectionInfoRef;
7373
collection: Collection;
7474
rollingIndexesService: RollingIndexesService;
75+
pollingIntervalRef: {
76+
regularIndexes: ReturnType<typeof setInterval> | null;
77+
searchIndexes: ReturnType<typeof setInterval> | null;
78+
};
7579
};
7680
export type IndexesThunkDispatch<A extends Action = AnyAction> = ThunkDispatch<
7781
RootState,

packages/compass-indexes/src/modules/regular-indexes.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ describe('regular-indexes module', function () {
467467

468468
it('starts and stops the polling', async function () {
469469
const pollInterval = 5000;
470-
const tabId = 'my-tab';
471470

472471
const collection = createMockCollection();
473472

@@ -498,7 +497,7 @@ describe('regular-indexes module', function () {
498497
// initial load
499498
expect(indexesStub.callCount).to.equal(1);
500499

501-
store.dispatch(startPollingRegularIndexes(tabId));
500+
store.dispatch(startPollingRegularIndexes());
502501

503502
// poll
504503
clock.tick(pollInterval);
@@ -513,15 +512,15 @@ describe('regular-indexes module', function () {
513512
await waitForStatus('READY');
514513

515514
// stop
516-
store.dispatch(stopPollingRegularIndexes(tabId));
515+
store.dispatch(stopPollingRegularIndexes());
517516

518517
// no more polling
519518
clock.tick(pollInterval);
520519
expect(indexesStub.callCount).to.equal(3);
521520
await waitForStatus('READY');
522521

523522
// open again
524-
store.dispatch(startPollingRegularIndexes(tabId));
523+
store.dispatch(startPollingRegularIndexes());
525524

526525
// won't execute immediately
527526
expect(indexesStub.callCount).to.equal(3);
@@ -540,7 +539,7 @@ describe('regular-indexes module', function () {
540539
await waitForStatus('READY');
541540

542541
// clean up
543-
store.dispatch(stopPollingRegularIndexes(tabId));
542+
store.dispatch(stopPollingRegularIndexes());
544543

545544
expect(collection.fetch.callCount).to.equal(0);
546545
});

0 commit comments

Comments
 (0)