Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
}
}

public start() {
this.doneHandler(null);
public async start(): Promise<void> {
await this.doneHandler(null);
}

public on(verb: string, cb: ObjectCallback<T>) {
Expand Down
38 changes: 38 additions & 0 deletions src/cache_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,44 @@ describe('ListWatchCache', () => {

expect(addedList.length).to.equal(1);
});
it('should resolve start promise after seeding the cache', async () => {
const fakeWatch = mock.mock(Watch);
const list: V1Namespace[] = [
{
metadata: {
name: 'name1',
} as V1ObjectMeta,
} as V1Namespace,
{
metadata: {
name: 'name2',
} as V1ObjectMeta,
} as V1Namespace,
];
const listObj = {
metadata: {
resourceVersion: '12345',
} as V1ListMeta,
items: list,
} as V1NamespaceList;

const listFn: ListPromise<V1Namespace> = function(): Promise<{
response: http.IncomingMessage;
body: V1NamespaceList;
}> {
return new Promise<{ response: http.IncomingMessage; body: V1NamespaceList }>((resolve) => {
// setImmediate will defer the resolve to the next message loop to keep the list from being immediately available
setImmediate(() => {
resolve({ response: {} as http.IncomingMessage, body: listObj });
});
});
};
const cache = new ListWatch('/some/path', mock.instance(fakeWatch), listFn, false);
const startPromise: Promise<void> = cache.start();
expect(cache.list().length).to.equal(0);
await startPromise;
expect(cache.list().length).to.equal(2);
});
});

describe('delete items', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/informer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const DELETE: string = 'delete';
export interface Informer<T> {
on(verb: string, fn: ObjectCallback<T>);
off(verb: string, fn: ObjectCallback<T>);
start();
start(): Promise<void>;
}

export function makeInformer<T>(
Expand Down