Skip to content

Commit

Permalink
ci: test on push and pr
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed Feb 13, 2024
1 parent 97a51a9 commit 790051d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Test
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.7'
- run: go test -v
- run: go build .

stress-test:
runs-on: ubuntu-latest
container: ghcr.io/catthehacker/ubuntu:act-latest
services:
mongodb:
image: mongo
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: user
MONGO_INITDB_ROOT_PASSWORD: password
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.7'
- name: Install k6
run: curl https://github.com/grafana/k6/releases/download/v0.49.0/k6-v0.49.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1
- run: go build .
- run: ./ad-service & sleep 5 && go run scripts/seed.go 2500 && ./k6 run -u 100 scripts/stress.js
env:
GIN_MODE: release
MONGODB_URI: mongodb://user:password@mongo:27017
2 changes: 1 addition & 1 deletion scripts/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func sendAd(ad *AdPayload) {
return
}

resp, err := http.Post("http://localhost:8080/api/v1/ad", "application/json", bytes.NewBuffer(jsonData))
resp, err := http.Post("http://127.0.0.1:8080/api/v1/ad", "application/json", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error sending ad to API", err)
return
Expand Down
2 changes: 1 addition & 1 deletion scripts/stress.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const randomPlatform = () => ["android", "ios", "web", ""][Math.floor(Math.rando
const randomCountry = () => ["US", "CA", "MX", "BR", "JP", "KR", "CN", "RU", "AU", "NZ", "TW", ""][Math.floor(Math.random() * 12)];

export default function () {
let url = `http://localhost:8080/api/v1/ad?offset=${randomOffset()}&limit=${randomLimit()}`;
let url = `http://127.0.0.1:8080/api/v1/ad?offset=${randomOffset()}&limit=${randomLimit()}`;

const age = randomAge();
if (age) url += `&age=${age}`;
Expand Down

0 comments on commit 790051d

Please sign in to comment.