Skip to content

Commit 618a683

Browse files
committed
address PR comments
1 parent 0d21433 commit 618a683

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

packages/compass-global-writes/src/components/states/incomplete-sharding-setup.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
css,
77
ButtonVariant,
88
Link,
9+
SpinLoader,
910
} from '@mongodb-js/compass-components';
1011
import React from 'react';
1112
import ShardKeyMarkup from '../shard-key-markup';
@@ -68,6 +69,7 @@ export function IncompleteShardingSetup({
6869
onClick={onResume}
6970
variant={ButtonVariant.Default}
7071
isLoading={isSubmittingForSharding}
72+
loadingIndicator={<SpinLoader />}
7173
className={manageBtnStyles}
7274
>
7375
Enable Global Writes

packages/compass-global-writes/src/store/index.spec.ts

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function createStore({
9090
} = {}): GlobalWritesStore {
9191
const atlasService = {
9292
authenticatedFetch: (uri: string) => {
93-
if (uri.includes(`/geoSharding`) && failsOnShardingRequest()) {
93+
if (uri.endsWith(`/geoSharding`) && failsOnShardingRequest()) {
9494
return Promise.reject(new Error('Failed to shard'));
9595
}
9696

@@ -313,7 +313,7 @@ describe('GlobalWritesStore Store', function () {
313313
});
314314
});
315315

316-
it('incomplete setup -> shard key correct', async function () {
316+
it('incomplete setup -> sharding -> shard key correct', async function () {
317317
// initial state -> incomplete shardingSetup
318318
clock = sinon.useFakeTimers({
319319
shouldAdvanceTime: true,
@@ -335,12 +335,78 @@ describe('GlobalWritesStore Store', function () {
335335
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
336336
);
337337
await promise;
338+
339+
// sharding
340+
expect(store.getState().status).to.equal('SHARDING');
341+
342+
// done
338343
clock.tick(POLLING_INTERVAL);
339344
await waitFor(() => {
340345
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
341346
});
342347
});
343348

349+
it('incomplete setup -> sharding -> incomplete setup (request was cancelled)', async function () {
350+
// initial state -> incomplete shardingSetup
351+
clock = sinon.useFakeTimers({
352+
shouldAdvanceTime: true,
353+
});
354+
const store = createStore({
355+
isNamespaceManaged: () => false,
356+
hasShardKey: () => true,
357+
});
358+
await waitFor(() => {
359+
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
360+
expect(store.getState().managedNamespace).to.be.undefined;
361+
});
362+
363+
// user asks to resume geosharding
364+
const promise = store.dispatch(resumeManagedNamespace());
365+
expect(store.getState().status).to.equal(
366+
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
367+
);
368+
await promise;
369+
370+
// sharding
371+
expect(store.getState().status).to.equal('SHARDING');
372+
373+
// user cancels the request - we go back to incomplete
374+
const promise2 = store.dispatch(cancelSharding());
375+
await promise2;
376+
clock.tick(POLLING_INTERVAL);
377+
await waitFor(() => {
378+
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
379+
});
380+
});
381+
382+
it('incomplete setup -> incomplete setup (failed manage attempt)', async function () {
383+
// initial state -> incomplete shardingSetup
384+
clock = sinon.useFakeTimers({
385+
shouldAdvanceTime: true,
386+
});
387+
const store = createStore({
388+
isNamespaceManaged: () => false,
389+
hasShardKey: () => true,
390+
failsOnShardingRequest: () => true,
391+
});
392+
await waitFor(() => {
393+
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
394+
expect(store.getState().managedNamespace).to.be.undefined;
395+
});
396+
397+
// user asks to resume geosharding
398+
const promise = store.dispatch(resumeManagedNamespace());
399+
expect(store.getState().status).to.equal(
400+
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
401+
);
402+
await promise;
403+
404+
// it failed
405+
await waitFor(() => {
406+
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
407+
});
408+
});
409+
344410
it('valid shard key -> incomplete', async function () {
345411
// initial state === shard key correct
346412
const store = createStore({

packages/compass-global-writes/src/store/reducer.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
492492
) {
493493
return {
494494
...state,
495-
status: ShardingStatuses.UNSHARDED,
495+
status: state.shardKey
496+
? ShardingStatuses.INCOMPLETE_SHARDING_SETUP
497+
: ShardingStatuses.UNSHARDED,
496498
shardingError: undefined,
497499
};
498500
}
@@ -511,6 +513,34 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
511513
};
512514
}
513515

516+
if (
517+
isAction<SubmittingForShardingErroredAction>(
518+
action,
519+
GlobalWritesActionTypes.SubmittingForShardingErrored
520+
) &&
521+
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR
522+
) {
523+
return {
524+
...state,
525+
managedNamespace: undefined,
526+
status: ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR,
527+
};
528+
}
529+
530+
if (
531+
isAction<SubmittingForShardingErroredAction>(
532+
action,
533+
GlobalWritesActionTypes.SubmittingForShardingErrored
534+
) &&
535+
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_INCOMPLETE
536+
) {
537+
return {
538+
...state,
539+
managedNamespace: undefined,
540+
status: ShardingStatuses.INCOMPLETE_SHARDING_SETUP,
541+
};
542+
}
543+
514544
if (
515545
isAction<UnmanagingNamespaceStartedAction>(
516546
action,

0 commit comments

Comments
 (0)