Skip to content

testing: T.Setenv can be called after T.Parallel #55128

Closed

Description

@noi

What version of Go are you using (go version)?

$ go version
go version go1.19.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="$HOME/.cache/go-build"
GOENV="$HOME/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="$HOME/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="$HOME/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="$HOME/dev/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1463438795=/tmp/go-build -gno-record-gcc-switches"

What did you do?

T.Setenv will panic if it be called after T.Parallel but it can be called in T.Run.

Sample code:
https://go.dev/play/p/54VhJKYpb_q

What did you expect to see?

I think it should panic even in T.Run.

What did you see instead?

Those tests become flaky without panic.

Others

I'm trying to fix this issue now.

Activity

  1. ianlancetaylor commented on Sep 18, 2022

    @ianlancetaylor
    Contributor

    I'm not sure what is wrong with calling t.Setenv in a function passed to t.Run. It would be wrong if the function calls t.Parallel, but if it doesn't, it should work reliably. It may not do what you want, but it shouldn't be flaky. Do I misunderstand?

  2. ZekeLu commented on Sep 18, 2022

    @ZekeLu
    Contributor

    I think noi@ means that a sub test is flaky when it calls t.Setenv while its parent has called t.Parallel. This looks plausible.

  3. ianlancetaylor commented on Sep 18, 2022

    @ianlancetaylor
    Contributor

    Ah, yes, I see. We need to walk the parent list or something.

  4. noi commented on Sep 18, 2022

    @noi
    ContributorAuthor

    Thank you for your replying!
    I'm sorry for confusing you by my bad English. ZekeLu is right, I wanted to say like that.

    I'm trying to fix this issue by passing isAncestorParalell to sub test in t.Run.

  5. gopherbot commented on Sep 18, 2022

    @gopherbot
    Contributor

    Change https://go.dev/cl/431101 mentions this issue: testing: fix T.Setenv for not calling to it in parallel tests

  6. noi commented on Sep 18, 2022

    @noi
    ContributorAuthor

    I sent my changes, so I would appreciate it if you could review it when you have time🙇‍♂️

  7. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Sep 19, 2022
  8. added this to the Backlog milestone on Sep 19, 2022
  9. gopherbot commented on Sep 25, 2022

    @gopherbot
    Contributor

    Change https://go.dev/cl/434115 mentions this issue: testing: update description of Setenv

  10. added a commit that references this issue on Sep 29, 2022
    a14ac86
  11. locked and limited conversation to collaborators on Sep 28, 2023
  12. added a commit that references this issue on Feb 20, 2024
    d6ca244
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions