Skip to content

Commit 97481d8

Browse files
committed
fix: add missing await when pushing workloads to queue
1 parent 614fc72 commit 97481d8

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/supervisor/watchers/handlers/pod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function handleReadyPod(
5959

6060
const workload = workloadToScan[0];
6161
if (workloadToScan.length > 0) {
62-
workloadsToScanQueue.push({
62+
await workloadsToScanQueue.pushAsync({
6363
key: workload.uid,
6464
workloadMetadata: workloadToScan,
6565
enqueueTimestampMs: Date.now(),

test/unit/scanner/scan-results-caching.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ describe('scan results caching', () => {
3636
it('stores workload images to cache and pushes to queue when not already seen', async () => {
3737
// Arrange
3838
const queuePushMock = jest
39-
.spyOn(workloadsToScanQueue, 'push')
40-
.mockReturnValue();
39+
.spyOn(workloadsToScanQueue, 'pushAsync')
40+
.mockResolvedValue(undefined);
4141
const setWorkloadImageAlreadyScannedMock = jest
4242
.spyOn(state, 'setWorkloadImageAlreadyScanned')
4343
.mockReturnValue(true);
@@ -65,8 +65,8 @@ describe('scan results caching', () => {
6565
it('stores images to cache and pushes to queue when imageId is different', async () => {
6666
// Arrange
6767
const queuePushMock = jest
68-
.spyOn(workloadsToScanQueue, 'push')
69-
.mockReturnValue();
68+
.spyOn(workloadsToScanQueue, 'pushAsync')
69+
.mockResolvedValue(undefined);
7070
const setWorkloadImageAlreadyScannedMock = jest
7171
.spyOn(state, 'setWorkloadImageAlreadyScanned')
7272
.mockReturnValue(true);
@@ -103,8 +103,8 @@ describe('scan results caching', () => {
103103
workload.imageId,
104104
);
105105
const queuePushMock = jest
106-
.spyOn(workloadsToScanQueue, 'push')
107-
.mockReturnValue();
106+
.spyOn(workloadsToScanQueue, 'pushAsync')
107+
.mockResolvedValue(undefined);
108108
const setWorkloadImageAlreadyScannedMock = jest
109109
.spyOn(state, 'setWorkloadImageAlreadyScanned')
110110
.mockReturnValue(true);

test/unit/supervisor/pod-watch-handler-caches.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import sleep from 'sleep-promise';
44
import * as YAML from 'yaml';
55
// NOTE: Very important that the mock is set up before application code is imported!
66
let pushCallCount = 0;
7-
const asyncQueueSpy = jest
8-
.spyOn(async, 'queue')
9-
.mockReturnValue({ error: () => {}, push: () => pushCallCount++ } as any);
7+
const asyncQueueSpy = jest.spyOn(async, 'queue').mockReturnValue({
8+
error: () => {},
9+
pushAsync: async () => pushCallCount++,
10+
} as any);
1011

1112
import { V1PodSpec, V1Pod } from '@kubernetes/client-node';
1213
import { IWorkload } from '../../../src/transmitter/types';
@@ -56,19 +57,19 @@ describe('image and workload image cache', () => {
5657
it('pushed data to send', async () => {
5758
await pod.podWatchHandler(podObject);
5859
await sleep(500);
59-
expect(pushCallCount).toEqual(1);
60+
expect(pushCallCount).toEqual(2);
6061
});
6162

6263
it('cached info, no data pushed to send', async () => {
6364
await pod.podWatchHandler(podObject);
6465
await sleep(500);
65-
expect(pushCallCount).toEqual(1);
66+
expect(pushCallCount).toEqual(2);
6667
});
6768

6869
it('new image parsed, workload is cached', async () => {
6970
workloadMetadata[0].imageId = 'newImageName';
7071
await pod.podWatchHandler(podObject);
7172
await sleep(1000);
72-
expect(pushCallCount).toEqual(2);
73+
expect(pushCallCount).toEqual(3);
7374
});
7475
});

0 commit comments

Comments
 (0)