Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

race detected when using run as a test helper to perform parallel tests #1091

Closed
kim-seungsu-edash opened this issue Dec 4, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@kim-seungsu-edash
Copy link

Description

  • Summary: race detected when using run as a test helper to perform parallel tests
  • Environment: go version go1.23.0 darwin/arm64, runn v0.122.1

🛠 Steps to Reproduce

  1. Step 1: test setup

main_test.go

package main

import (
	"context"
	"encoding/json"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/k1LoW/runn"
)

type HealthCheck struct{}

func (HealthCheck) ServeHTTP(w http.ResponseWriter, r *http.Request) { //nostyle:recvtype
	resp := map[string]string{
		"message": "ok",
	}
	jsonBody, err := json.Marshal(resp)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	w.Write(jsonBody)
}

func TestHealthCheck(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name  string
		pathp string
	}{
		{
			name:  "healthz1",
			pathp: "./book.yml",
		},
		{
			name:  "healthz2",
			pathp: "./book.yml",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()

			ctx := context.Background()
			ts := httptest.NewServer(HealthCheck{})
			t.Cleanup(ts.Close)
			opts := []runn.Option{
				runn.T(t),
				runn.Runner("req", ts.URL),
			}
			o, err := runn.Load("./book.yml", opts...)
			if err != nil {
				t.Fatal(err)
			}
			if err := o.RunN(ctx); err != nil {
				t.Fatal(err)
			}
		})
	}
}

book.yml

desc: Go Test Helper
runners:
  req: http://localhost:8080
steps:
  healthz:
    desc: health check
    req:
      /healthz:
        get:
          body:
            application/json: null
    test: |
      steps.healthz.res.status == 200
      && steps.healthz.res.body.message == "ok"
  1. Step 2: go test -race ./...

📷 Screenshots and Logs

Logs
==================
WARNING: DATA RACE
Write at 0x000106fe49d0 by goroutine 24:
  github.com/expr-lang/expr/ast.(*base).SetType()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/ast/node.go:49 +0x40
  github.com/expr-lang/expr/ast.(*IdentifierNode).SetType()
      <autogenerated>:1 +0x20
  github.com/expr-lang/expr/checker.(*checker).visit()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:171 +0x4d4
  github.com/expr-lang/expr/checker.(*checker).functionReturnType()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:588 +0x5c
  github.com/expr-lang/expr/checker.(*checker).CallNode()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:567 +0x30
  github.com/expr-lang/expr/checker.(*checker).visit()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:151 +0x208
  github.com/expr-lang/expr/checker.Check()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:62 +0xa0
  github.com/expr-lang/expr/checker.ParseCheck()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:45 +0x94
  github.com/expr-lang/expr.Compile()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/expr.go:208 +0x3e8
  github.com/k1LoW/runn.EvalWithTrace()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/eval.go:37 +0x168
  github.com/k1LoW/runn.(*testRunner).run()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/test.go:54 +0x60
  github.com/k1LoW/runn.(*testRunner).Run()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/test.go:46 +0x8b8
  github.com/k1LoW/runn.(*operator).runStep.func1()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:283 +0x1610
  github.com/k1LoW/runn.(*operator).runStep()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:363 +0x8f4
  github.com/k1LoW/runn.(*operator).runInternal()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:1199 +0x764
  github.com/k1LoW/runn.(*operator).run.func2()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:966 +0x110
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x40

Previous write at 0x000106fe49d0 by goroutine 25:
  github.com/expr-lang/expr/ast.(*base).SetType()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/ast/node.go:49 +0x40
  github.com/expr-lang/expr/ast.(*IdentifierNode).SetType()
      <autogenerated>:1 +0x20
  github.com/expr-lang/expr/checker.(*checker).visit()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:171 +0x4d4
  github.com/expr-lang/expr/checker.(*checker).functionReturnType()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:588 +0x5c
  github.com/expr-lang/expr/checker.(*checker).CallNode()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:567 +0x30
  github.com/expr-lang/expr/checker.(*checker).visit()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:151 +0x208
  github.com/expr-lang/expr/checker.Check()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:62 +0xa0
  github.com/expr-lang/expr/checker.ParseCheck()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/checker/checker.go:45 +0x94
  github.com/expr-lang/expr.Compile()
      /Users/kimseungsu/.go/pkg/mod/github.com/expr-lang/[email protected]/expr.go:208 +0x3e8
  github.com/k1LoW/runn.EvalWithTrace()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/eval.go:37 +0x168
  github.com/k1LoW/runn.(*testRunner).run()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/test.go:54 +0x60
  github.com/k1LoW/runn.(*testRunner).Run()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/test.go:46 +0x8b8
  github.com/k1LoW/runn.(*operator).runStep.func1()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:283 +0x1610
  github.com/k1LoW/runn.(*operator).runStep()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:363 +0x8f4
  github.com/k1LoW/runn.(*operator).runInternal()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:1199 +0x764
  github.com/k1LoW/runn.(*operator).run.func2()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:966 +0x110
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x40

Goroutine 24 (running) created at:
  testing.(*T).Run()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x5e0
  github.com/k1LoW/runn.(*operator).run()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:960 +0x73c
  github.com/k1LoW/runn.(*operatorN).runN.func1()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:1709 +0x1e0
  github.com/k1LoW/concgroup.(*Group).GoMulti.func1()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/concgroup.go:62 +0x124
  golang.org/x/sync/errgroup.(*Group).Go.func1()
      /Users/kimseungsu/.go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x7c

Goroutine 25 (running) created at:
  testing.(*T).Run()
      /opt/homebrew/Cellar/go/1.23.0/libexec/src/testing/testing.go:1743 +0x5e0
  github.com/k1LoW/runn.(*operator).run()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:960 +0x73c
  github.com/k1LoW/runn.(*operatorN).runN.func1()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/operator.go:1709 +0x1e0
  github.com/k1LoW/concgroup.(*Group).GoMulti.func1()
      /Users/kimseungsu/.go/pkg/mod/github.com/k1!lo!w/[email protected]/concgroup.go:62 +0x124
  golang.org/x/sync/errgroup.(*Group).Go.func1()
      /Users/kimseungsu/.go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x7c
==================
--- FAIL: TestHealthCheck (0.00s)
    --- FAIL: TestHealthCheck/healthz2 (0.01s)
        --- FAIL: TestHealthCheck/healthz2/./book.yml(fd8d83d6d14a8f033bf873e78faf2138b174004d) (0.00s)
            testing.go:1399: race detected during execution of test
    --- FAIL: TestHealthCheck/healthz1 (0.01s)
        --- FAIL: TestHealthCheck/healthz1/./book.yml(fd8d83d6d14a8f033bf873e78faf2138b174004d) (0.00s)
            testing.go:1399: race detected during execution of test
FAIL
FAIL	gotest	0.894s
FAIL
@k1LoW k1LoW added the bug Something isn't working label Dec 4, 2024
@k1LoW k1LoW self-assigned this Dec 4, 2024
@k1LoW
Copy link
Owner

k1LoW commented Dec 4, 2024

@kim-seungsu-edash Thank you for your report!!

@k1LoW
Copy link
Owner

k1LoW commented Dec 5, 2024

Fixed at v0.122.2. Thank you!

@kim-seungsu-edash
Copy link
Author

@k1LoW
It has been confirmed that no data race occurred. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants