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

chore(search-indexes): only poll search indexes when there is connectivity to the cluster #4935

Merged
merged 5 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {
screen,
fireEvent,
within,
waitFor,
} from '@testing-library/react';
import { expect } from 'chai';
import sinon from 'sinon';
import userEvent from '@testing-library/user-event';
import type { Document } from 'mongodb';

import { SearchIndexesTable } from './search-indexes-table';
import { POLLING_INTERVAL, SearchIndexesTable } from './search-indexes-table';
import { SearchIndexesStatuses } from '../../modules/search-indexes';
import { searchIndexes as indexes } from './../../../test/fixtures/search-indexes';

Expand Down Expand Up @@ -184,4 +185,25 @@ describe('SearchIndexesTable Component', function () {
expect(onEditIndexSpy.callCount).to.equal(1);
});
});

describe('connectivity', function () {
it('does not poll the index for changes in offline mode', function () {
const onPollIndexesSpy = sinon.spy();
renderIndexList({ onPollIndexes: onPollIndexesSpy, isWritable: false });

expect(onPollIndexesSpy.callCount).to.equal(0);
});

it('does poll the index for changes in online mode', async function () {
const onPollIndexesSpy = sinon.spy();
renderIndexList({ onPollIndexes: onPollIndexesSpy, isWritable: true });

await waitFor(
() => {
expect(onPollIndexesSpy.callCount).to.be.greaterThanOrEqual(1);
},
{ timeout: POLLING_INTERVAL * 2 }
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import { IndexesTable } from '../indexes-table';
import IndexActions from './search-index-actions';
import { ZeroGraphic } from './zero-graphic';

const POLLING_INTERVAL = 5000;
export const POLLING_INTERVAL = 5000;

function noop() {
return;
}

type SearchIndexesTableProps = {
indexes: SearchIndex[];
Expand Down Expand Up @@ -174,11 +178,15 @@ export const SearchIndexesTable: React.FunctionComponent<
onPollIndexes,
}) => {
useEffect(() => {
if (!isWritable) {
return noop;
kmruiz marked this conversation as resolved.
Show resolved Hide resolved
}

const id = setInterval(onPollIndexes, POLLING_INTERVAL);
return () => {
clearInterval(id);
};
}, [onPollIndexes]);
}, [onPollIndexes, isWritable]);
kmruiz marked this conversation as resolved.
Show resolved Hide resolved

if (!isReadyStatus(status)) {
// If there's an error or the search indexes are still pending or search
Expand Down