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
18 changes: 10 additions & 8 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [20.x, 22.x, 24.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -25,16 +25,18 @@ jobs:
- name: Verify lint
run: npm run lint
- name: Show interfaces
run: sudo ip r
run: sudo ip route show
- name: Get default interface
run: sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'
- name: Test cable
run: bin/index.js cable && bin/index.js stop
run: LOG_THROTTLE=true bin/index.js cable && bin/index.js stop
- name: Test configuration
run: bin/index.js throttle --up 330 --down 780 --rtt 200 && bin/index.js stop
run: LOG_THROTTLE=true bin/index.js throttle --up 330 --down 780 --rtt 200 && bin/index.js stop
- name: Test localhost
run: bin/index.js --rtt 200 --localhost && bin/index.js stop --localhost
run: LOG_THROTTLE=true bin/index.js --rtt 200 --localhost && bin/index.js stop --localhost
- name: Test config file
run: bin/index.js --config test/config.json && bin/index.js stop
run: LOG_THROTTLE=true bin/index.js --config test/config.json && bin/index.js stop
- name: Test packet loss
run: bin/index.js throttle --up 330 --down 780 --rtt 200 --packetLoss 10 && bin/index.js stop
run: LOG_THROTTLE=true bin/index.js throttle --up 330 --down 780 --rtt 200 --packetLoss 10 && bin/index.js stop
- name: Test packet loss and profile
run: bin/index.js 3g --packetLoss 10 && bin/index.js stop
run: LOG_THROTTLE=true bin/index.js 3g --packetLoss 10 && bin/index.js stop
23 changes: 17 additions & 6 deletions lib/tc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import shell from './shell.js';
import sudo from './sudo.js';

const delay = (ms) => new Promise((result) => setTimeout(result, ms));

async function getDefaultInterface() {
const result = await shell(
"sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'",
{
shell: true
}
);
const command =
"sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'";
const result = await shell(command);

if (result.stdout.length === 0 && result.stderr.length > 0) {
throw new Error(
'There was an error getting the default interface:\n\n' + result.stderr
);
} else if (result.stdout.length === 0) {
// lets do one retry
// The GitHub Actions sometimes cannot find the interface
await delay(1000);
const result = await shell(command);
if (result.stdout.length === 0) {
const result = await shell('sudo ip route show');
throw new Error(
`There was an error getting the default interface ${result.stdout}`
);
}
return result.stdout;
}

return result.stdout;
Expand Down