Skip to content

Commit

Permalink
Fix exponential backoff implementation and add github actions to vali…
Browse files Browse the repository at this point in the history
…date it. (#17)

* test: add github action for testing.

* chore: add another action for build.

* fix the build argument.

* fix: check for overflow in attempt too.
  • Loading branch information
abeaumont authored Feb 15, 2022
1 parent f59bcd6 commit 2df6b92
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Build with Gradle
uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
with:
arguments: shadowJar
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Test with Gradle
uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
with:
arguments: test
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ clean:
build:
./gradlew shadowJar

.PHONY: test
test:
./gradlew test

.PHONY: docker-example
docker-example: build
cp agent/build/libs/pyroscope.jar example/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ final class ExponentialBackoff {
final int error() {
attempt += 1;
int multiplier = cap / base;
if ((multiplier >> attempt) > 0) {
// from https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.19
// "If the promoted type of the left-hand operand is int, then only the five lowest-order bits of the right-hand operand are used as the shift distance".
if (attempt < 32 && (multiplier >> attempt) > 0) {
multiplier = 1 << attempt;
}
return random.nextInt(base * multiplier);
Expand Down

0 comments on commit 2df6b92

Please sign in to comment.