Skip to content

Commit 4938b92

Browse files
add tests for close garbage collector and expiration processor
1 parent f12ad7d commit 4938b92

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

tests/unit/gc/GarbageCollector.spec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,47 @@ describe('garbage collector', function garbageCollector() {
9292
.setAttribute('target.owner', ownerId);
9393
gcTask.processActionEntry(action, done);
9494
});
95+
96+
describe('close() garbage collector', () => {
97+
it('should call close on the consumer when it exists', done => {
98+
const gcWithConsumer = new GarbageCollector({
99+
kafkaConfig: {},
100+
s3Config: { host: 'localhost', port: 7777 },
101+
gcConfig: {
102+
topic: 'backbeat-gc',
103+
auth: { type: 'account', account: 'bart' },
104+
consumer: { groupId: 'backbeat-gc-consumer-group' },
105+
},
106+
});
107+
let closeCalled = false;
108+
gcWithConsumer._consumer = {
109+
close: cb => {
110+
closeCalled = true;
111+
cb();
112+
},
113+
};
114+
gcWithConsumer.close(err => {
115+
assert.ifError(err);
116+
assert.strictEqual(closeCalled, true);
117+
done();
118+
});
119+
});
120+
121+
it('should call callback immediately when consumer is null', done => {
122+
const gcNoConsumer = new GarbageCollector({
123+
kafkaConfig: {},
124+
s3Config: { host: 'localhost', port: 7777 },
125+
gcConfig: {
126+
topic: 'backbeat-gc',
127+
auth: { type: 'account', account: 'bart' },
128+
consumer: { groupId: 'backbeat-gc-consumer-group' },
129+
},
130+
});
131+
assert.strictEqual(gcNoConsumer._consumer, null);
132+
gcNoConsumer.close(err => {
133+
assert.ifError(err);
134+
done();
135+
});
136+
});
137+
});
95138
});

tests/unit/lifecycle/LifecycleObjectExpirationProcessor.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,37 @@ describe('LifecycleObjectExpirationProcessor', () => {
2323
config.extensions.lifecycle.objectTasksTopic,
2424
);
2525
});
26+
27+
describe('close() expiration processor', () => {
28+
it('should call close on consumers when they exist', done => {
29+
let closeCalled = false;
30+
objectProcessor._consumers = {
31+
close: cb => {
32+
closeCalled = true;
33+
cb();
34+
},
35+
};
36+
objectProcessor.close(err => {
37+
assert.ifError(err);
38+
assert.strictEqual(closeCalled, true);
39+
done();
40+
});
41+
});
42+
43+
it('should call callback immediately when consumers is null', done => {
44+
assert.strictEqual(objectProcessor._consumers, null);
45+
objectProcessor.close(err => {
46+
assert.ifError(err);
47+
done();
48+
});
49+
});
50+
51+
it('should clear deleteInactiveCredentialsInterval if set', done => {
52+
objectProcessor._deleteInactiveCredentialsInterval = setInterval(() => {}, 100000);
53+
objectProcessor.close(err => {
54+
assert.ifError(err);
55+
done();
56+
});
57+
});
58+
});
2659
});

0 commit comments

Comments
 (0)