From 93f2d1d05f9ad8546e64a78cc8832164ac54ec6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Tue, 22 Jun 2021 11:43:18 +0200 Subject: [PATCH] WIP Add test and xk6 CI workflows --- .github/workflows/test.yml | 54 +++++++++++++++++++++++++++++++++++ .github/workflows/xk6-test.js | 39 +++++++++++++++++++++++++ .github/workflows/xk6.yml | 48 +++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/xk6-test.js create mode 100644 .github/workflows/xk6.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..de0ccb8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,54 @@ +name: Test +on: + # Enable manually triggering this workflow via the API or web UI + workflow_dispatch: + push: + branches: + - master + tags: + - v* + pull_request: + +defaults: + run: + shell: bash + +jobs: + lint: + runs-on: ubuntu-latest + env: + GOLANG_CI_VERSION: "1.41.1" + GO111MODULE: 'on' + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16.x + - name: Install golangci-lint + working-directory: /tmp + run: go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANG_CI_VERSION" + - name: Run linters + run: | + golangci-lint run --out-format=tab ./... + + test: + strategy: + fail-fast: false + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16.x + - name: Run tests + run: | + set -x + go version + export GOMAXPROCS=2 + go test -p 2 -race -timeout 60s ./... diff --git a/.github/workflows/xk6-test.js b/.github/workflows/xk6-test.js new file mode 100644 index 0000000..27a089c --- /dev/null +++ b/.github/workflows/xk6-test.js @@ -0,0 +1,39 @@ +import { sleep } from 'k6'; +import exec from 'k6/x/execution'; + +export let options = { + scenarios: { + shared: { + executor: 'shared-iterations', + vus: 50, + iterations: 500, + }, + rar: { + executor: 'ramping-arrival-rate', + startTime: '10s', + startRate: 20, + timeUnit: '1s', + preAllocatedVUs: 0, + maxVUs: 40, + stages: [ + { target: 50, duration: '5s' }, + { target: 0, duration: '5s' }, + ], + gracefulStop: '0s', + }, + } +} + +function logObj(msg, o) { + console.log(msg, JSON.stringify(o, Object.keys(o).sort())); +} + +export default function () { + const vuStats = exec.getVUStats(); + const scStats = exec.getScenarioStats(); + const testStats = exec.getTestInstanceStats(); + sleep(1); + logObj('VU stats:', vuStats); + logObj('Scenario stats:', scStats); + logObj('Test stats:', testStats); +} diff --git a/.github/workflows/xk6.yml b/.github/workflows/xk6.yml new file mode 100644 index 0000000..5211c0e --- /dev/null +++ b/.github/workflows/xk6.yml @@ -0,0 +1,48 @@ +name: xk6 +on: + # Enable manually triggering this workflow via the API or web UI + workflow_dispatch: + push: + branches: + - master + pull_request: + +defaults: + run: + shell: bash + +jobs: + test-xk6: + strategy: + matrix: + go: [stable, tip] + platform: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16.x + - name: Install Go tip + if: matrix.go == 'tip' + run: | + go install golang.org/dl/gotip@latest + gotip download + echo "GOROOT=$HOME/sdk/gotip" >> "$GITHUB_ENV" + echo "GOPATH=$HOME/go" >> "$GITHUB_ENV" + echo "$HOME/go/bin" >> "$GITHUB_PATH" + echo "$HOME/sdk/gotip/bin" >> "$GITHUB_PATH" + - name: Run tests + run: | + set -x + which go + go version + + go install github.com/k6io/xk6/cmd/xk6@master + GOPROXY="direct" xk6 build master \ + --output ./k6ext \ + --with github.com/k6io/xk6-execution="$(pwd)" + ./k6ext version + ./k6ext run --quiet --verbose .github/workflows/xk6-test.js