Skip to content

Commit 498aaa2

Browse files
committed
Make two attempts at updating keyserver
1 parent 7b4d1aa commit 498aaa2

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

__tests__/gpg.test.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,39 @@ describe("gpg", () => {
1616
expect(mockExec).toBeCalledTimes(1);
1717
});
1818

19-
it("uses the next keyserver in the pool if the previous fails", async () => {
20-
const failingServers = 3;
21-
let testedServers = 0;
19+
// NOTE: Currently disabled as the pool only contains one server
20+
// it("uses the next keyserver in the pool if the previous fails", async () => {
21+
// const failingServers = 3;
22+
// let testedServers = 0;
23+
24+
// mockExec.mockImplementation(() => {
25+
// testedServers++;
26+
// if (testedServers >= failingServers) {
27+
// return Promise.resolve(0);
28+
// } else {
29+
// return Promise.resolve(1);
30+
// }
31+
// });
32+
33+
// await refreshKeys();
34+
// expect(mockExec).toBeCalledTimes(3);
35+
// });
36+
37+
it("makes a second attempt if the keyserver fails", async () => {
38+
const attempts = 2;
39+
let tests = 0;
2240

2341
mockExec.mockImplementation(() => {
24-
testedServers++;
25-
if (testedServers >= failingServers) {
42+
tests++;
43+
if (tests >= attempts) {
2644
return Promise.resolve(0);
2745
} else {
2846
return Promise.resolve(1);
2947
}
3048
});
3149

3250
await refreshKeys();
33-
expect(mockExec).toBeCalledTimes(3);
51+
expect(mockExec).toBeCalledTimes(2);
3452
});
3553

3654
it("throws an error if all servers in the pool fails", async () => {

src/gpg.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ export async function refreshKeys() {
2525

2626
for (const server of pool) {
2727
core.debug(`Refreshing keys from ${server}`);
28+
// 1st try...
2829
if (await refreshKeysFromServer(server)) {
29-
core.debug(`Refresh successful`);
30+
core.debug(`Refresh successful on first attempt`);
31+
return;
32+
}
33+
34+
// 2nd try...
35+
if (await refreshKeysFromServer(server)) {
36+
core.debug(`Refresh successful on second attempt`);
3037
return;
3138
}
3239
core.debug(`Refresh failed`);

0 commit comments

Comments
 (0)