From 3fa767fbab5794e20a85467107b5ef9daa0c09cf Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Wed, 12 Feb 2020 10:12:15 +0000 Subject: [PATCH] cmd/govim: add test for racey cmd/go updates per golang.org/issues/37164 (#742) Test the racing of gopls' usages of go/packages which result in racey usages of cmd/go modifying go.mod. More detail in: https://github.com/golang/go/issues/36772#issuecomment-578933218 and preceding comments. The test below is an exact copy of the setup that triggered this failure. The go.mod is intentially "dirty" such that any calls to cmd/go will cause the require directive to be added. One such call happens in the initial workspace load, the other is triggered by GOVIMGoToDef if the initial call has not yet completed. Hence the two race to update go.mod --- .github/workflows/test.yml | 1 + .../scenario_bugs/bug_gopls_37164.txt | 60 +++++++++++++++++++ internal/cmd/genconfig/genconfig.go | 1 + 3 files changed, 62 insertions(+) create mode 100644 cmd/govim/testdata/scenario_bugs/bug_gopls_37164.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2004396e..52734bd56 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,7 @@ env: GH_USER: "x-access-token" GH_TOKEN: ${{ github.token }} GOVIM_TEST_RACE_SLOWDOWN: "1.5" + RACE_BUILD: "742" name: Go jobs: diff --git a/cmd/govim/testdata/scenario_bugs/bug_gopls_37164.txt b/cmd/govim/testdata/scenario_bugs/bug_gopls_37164.txt new file mode 100644 index 000000000..55c1c8223 --- /dev/null +++ b/cmd/govim/testdata/scenario_bugs/bug_gopls_37164.txt @@ -0,0 +1,60 @@ +# Test the racing of gopls' usages of go/packages which result in racey usages of +# cmd/go modifying go.mod. More detail in: +# +# https://github.com/golang/go/issues/36772#issuecomment-578933218 +# +# and preceding comments. The test below is an exact copy of the setup that triggered +# this failure. The go.mod is intentially "dirty" such that any calls to cmd/go +# will cause the require directive to be added. One such call happens in the initial +# workspace load, the other is triggered by GOVIMGoToDef if the initial call has not +# yet completed. Hence the two race to update go.mod + +[golang.org/issues/37164] skip +[short] skip 'Skip short because we sleep for GOVIM_ERRLOGMATCH_WAIT to ensure we don''t have any errors' + +vim ex 'e '$WORK/p.go +vim ex 'call cursor(5,17)' +vim ex 'GOVIMGoToDef' +sleep $GOVIM_ERRLOGMATCH_WAIT + +# Ensure go.mod has changed as we expect +cmp go.mod go.mod.golden + +# Use our own custom error check +# noerrcheck +errlogmatch -start -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*' + +-- go.mod -- +module mod.com/p + +go 1.12 + +replace mod.com/q => ./q + +-- go.mod.golden -- +module mod.com/p + +go 1.12 + +replace mod.com/q => ./q + +require mod.com/q v0.0.0-00010101000000-000000000000 +-- p.go -- +package p + +import "mod.com/q" + +const Name1 = q.Name +const Name2 = SameFile + +const SameFile = "samefile" + +-- q/go.mod -- +module mod.com/q + +go 1.12 + +-- q/q.go -- +package q + +const Name = "package q" diff --git a/internal/cmd/genconfig/genconfig.go b/internal/cmd/genconfig/genconfig.go index 64e46f271..f5dfa3a0c 100644 --- a/internal/cmd/genconfig/genconfig.go +++ b/internal/cmd/genconfig/genconfig.go @@ -270,6 +270,7 @@ env: GH_USER: "x-access-token" GH_TOKEN: ${{ github.token }} GOVIM_TEST_RACE_SLOWDOWN: "1.5" + RACE_BUILD: "742" name: Go jobs: