Skip to content

Commit ac8aa3a

Browse files
authored
Update test NodeJS to later version and retry logic for default interface (#95)
1 parent 7c44e5e commit ac8aa3a

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

.github/workflows/linux.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [16.x, 18.x, 20.x]
14+
node-version: [20.x, 22.x, 24.x]
1515
steps:
1616
- uses: actions/checkout@v2
1717
- name: Use Node.js ${{ matrix.node-version }}
@@ -25,16 +25,18 @@ jobs:
2525
- name: Verify lint
2626
run: npm run lint
2727
- name: Show interfaces
28-
run: sudo ip r
28+
run: sudo ip route show
29+
- name: Get default interface
30+
run: sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'
2931
- name: Test cable
30-
run: bin/index.js cable && bin/index.js stop
32+
run: LOG_THROTTLE=true bin/index.js cable && bin/index.js stop
3133
- name: Test configuration
32-
run: bin/index.js throttle --up 330 --down 780 --rtt 200 && bin/index.js stop
34+
run: LOG_THROTTLE=true bin/index.js throttle --up 330 --down 780 --rtt 200 && bin/index.js stop
3335
- name: Test localhost
34-
run: bin/index.js --rtt 200 --localhost && bin/index.js stop --localhost
36+
run: LOG_THROTTLE=true bin/index.js --rtt 200 --localhost && bin/index.js stop --localhost
3537
- name: Test config file
36-
run: bin/index.js --config test/config.json && bin/index.js stop
38+
run: LOG_THROTTLE=true bin/index.js --config test/config.json && bin/index.js stop
3739
- name: Test packet loss
38-
run: bin/index.js throttle --up 330 --down 780 --rtt 200 --packetLoss 10 && bin/index.js stop
40+
run: LOG_THROTTLE=true bin/index.js throttle --up 330 --down 780 --rtt 200 --packetLoss 10 && bin/index.js stop
3941
- name: Test packet loss and profile
40-
run: bin/index.js 3g --packetLoss 10 && bin/index.js stop
42+
run: LOG_THROTTLE=true bin/index.js 3g --packetLoss 10 && bin/index.js stop

lib/tc.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import shell from './shell.js';
22
import sudo from './sudo.js';
33

4+
const delay = (ms) => new Promise((result) => setTimeout(result, ms));
5+
46
async function getDefaultInterface() {
5-
const result = await shell(
6-
"sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'",
7-
{
8-
shell: true
9-
}
10-
);
7+
const command =
8+
"sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'";
9+
const result = await shell(command);
1110

1211
if (result.stdout.length === 0 && result.stderr.length > 0) {
1312
throw new Error(
1413
'There was an error getting the default interface:\n\n' + result.stderr
1514
);
15+
} else if (result.stdout.length === 0) {
16+
// lets do one retry
17+
// The GitHub Actions sometimes cannot find the interface
18+
await delay(1000);
19+
const result = await shell(command);
20+
if (result.stdout.length === 0) {
21+
const result = await shell('sudo ip route show');
22+
throw new Error(
23+
`There was an error getting the default interface ${result.stdout}`
24+
);
25+
}
26+
return result.stdout;
1627
}
1728

1829
return result.stdout;

0 commit comments

Comments
 (0)