diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..7c0b178 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,45 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + env: + # We overwrite this value to be 4 so + # the test can pass because if not the + # goroutines will not run in "parallel" + # and so the tests do not pass. + # 4 is because: + # * 1 Main run + # * 2 clients + # * 1 server + GOMAXPROCS: 4 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + # We install xorg-dev because of https://github.com/go-gl/glfw/issues/129#issuecomment-75928365 + # We install xvfb because of the error "The DISPLAY environment variable is missing" so we need + # to have a fake DISPLAY and xvfb does exactly that. + # Found it in https://stackoverflow.com/questions/834723/a-dev-null-equivilent-for-display-when-the-display-is-just-noise + - name: "Install xorg-dev and xvfb" + run: sudo apt-get install xvfb xorg-dev + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Build + run: make build + + - name: Test + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..73dc689 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.PHONY: help +help: ## Show this help + @grep -F -h "##" $(MAKEFILE_LIST) | grep -F -v grep -F | sed -e 's/:.*##/:##/' | column -t -s '##' + +.PHONY: build +build: + @go build -v ./... + +.PHONY: test +test: ## Run the tests + @xvfb-run go test -v ./... diff --git a/client/new.go b/client/new.go index 365f542..8616319 100644 --- a/client/new.go +++ b/client/new.go @@ -69,7 +69,7 @@ func New(ad *ActionDispatcher, rs *RouterStore, opt Options) error { var err error wsc, _, err = websocket.DefaultDialer.Dial(u.String(), nil) if err != nil { - return fmt.Errorf("failed to dial the server %q: %w", u, err) + return fmt.Errorf("failed to dial the server %q: %w", u.String(), err) } defer wsc.Close() diff --git a/integration/main_test.go b/integration/main_test.go index 9141a83..88d276c 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -3,6 +3,7 @@ package integration_test import ( "context" "os/exec" + "runtime" "testing" "time" @@ -23,10 +24,10 @@ import ( var ( // The actual one is 4 - serverGameTick = 3 * time.Second + serverGameTick = time.Second / 2 // The actual one is 60 - clientTPS = time.Second / 50 + clientTPS = time.Second / 30 ) func TestRun(t *testing.T) { @@ -63,7 +64,6 @@ func TestRun(t *testing.T) { Store: s, } - //i := inputer.NewEbiten() i := mock.NewMockInputer(ctrl) cs := client.NewCameraStore(cd, s, screenW, screenH) @@ -174,6 +174,7 @@ func TestRun(t *testing.T) { wait() resetDefault() + wait(serverGameTick) for _, p := range rooms.GetState().(server.RoomsState).Rooms[room].Game.Players.GetPlayers() { if p.Name == p1n { @@ -201,5 +202,6 @@ func wait(d ...time.Duration) { if len(d) == 0 { d = []time.Duration{clientTPS} } + runtime.Gosched() time.Sleep(d[0]) }