Skip to content

Unit tests for #1934 #1936

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

Merged
Merged
Changes from all 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
69 changes: 69 additions & 0 deletions src/cache_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,75 @@ describe('ListWatchCache', () => {
expect(listCalls).to.be.equal(2);
});

it('should list if the watch cannot be restarted from the latest resourceVersion with an ERROR event', async () => {
const fakeWatch = mock.mock(Watch);
const list: V1Pod[] = [];
const listObj = {
metadata: {
resourceVersion: '12345',
} as V1ListMeta,
items: list,
} as V1NamespaceList;

let listCalls = 0;
const listFn: ListPromise<V1Namespace> = function (): Promise<V1NamespaceList> {
return new Promise<V1NamespaceList>((resolve) => {
listCalls++;
resolve(listObj);
});
};
let promise = new Promise((resolve) => {
mock.when(
fakeWatch.watch(mock.anything(), mock.anything(), mock.anything(), mock.anything()),
).thenCall(() => {
resolve(new AbortController());
});
});

const informer = new ListWatch('/some/path', mock.instance(fakeWatch), listFn, false);

informer.start();
await promise;

const [, , watchHandler] = mock.capture(fakeWatch.watch).last();
watchHandler(
'ADDED',
{
metadata: {
name: 'name3',
} as V1ObjectMeta,
} as V1Namespace,
{ metadata: { resourceVersion: '23456' } },
);

await informer.stop();

let errorEmitted = false;
informer.on('error', () => (errorEmitted = true));

promise = new Promise((resolve) => {
mock.when(
fakeWatch.watch(mock.anything(), mock.anything(), mock.anything(), mock.anything()),
).thenCall(() => {
resolve(new AbortController());
});
});

informer.start();
await promise;

const [, , watchHandler2, doneHandler] = mock.capture(fakeWatch.watch).last();
watchHandler2('ERROR', {
code: 410,
});
doneHandler(undefined);
mock.verify(
fakeWatch.watch(mock.anything(), mock.anything(), mock.anything(), mock.anything()),
).twice();
expect(errorEmitted).to.equal(false);
expect(listCalls).to.be.equal(2);
});

it('should send label selector', async () => {
const APP_LABEL_SELECTOR = 'app=foo';

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.