Skip to content

Commit

Permalink
gopls/internal/test/integration/misc: fix flaky test
Browse files Browse the repository at this point in the history
The random base64 strings in gopls URLs caused occasional
spurious matches for the substring t1. This change uses
a non-base64 letter to eliminate this source of
nondeterminism.

Change-Id: I1db1dca8d93cc299b13b591567fa72b2227ac436
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576140
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
adonovan authored and gopherbot committed Apr 4, 2024
1 parent c9b0c65 commit 951bb40
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions gopls/internal/test/integration/misc/webserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,52 +90,53 @@ module example.com
-- a/a.go --
package a
// The '1' suffix is to reduce risk of spurious matches with other HTML substrings.
// The 'π' suffix is to elimimate spurious matches with other HTML substrings,
// in particular the random base64 secret tokens that appear in gopls URLs.
var V1, v1 = 0, 0
const C1, c1 = 0, 0
var Vπ, vπ = 0, 0
const Cπ, cπ = 0, 0
func F1()
func f1()
func ()
func ()
type T1 int
type t1 int
type int
type int
func (T1) M1() {}
func (T1) m1() {}
func (Tπ) Mπ() {}
func (Tπ) mπ() {}
func (t1) M1() {}
func (t1) m1() {}
func (tπ) Mπ() {}
func (tπ) mπ() {}
`
Run(t, files, func(t *testing.T, env *Env) {
uri1 := viewPkgDoc(t, env, "a/a.go")
doc := get(t, uri1)
// (Ideally our code rendering would also
// eliminate unexported symbols...)
checkMatch(t, true, doc, "var V1, v1 = .*0.*0")
checkMatch(t, true, doc, "const C1, c1 = .*0.*0")
checkMatch(t, true, doc, "var Vπ, vπ = .*0.*0")
checkMatch(t, true, doc, "const Cπ, cπ = .*0.*0")

// Unexported funcs/types/... must still be discarded.
checkMatch(t, true, doc, "F1")
checkMatch(t, false, doc, "f1")
checkMatch(t, true, doc, "T1")
checkMatch(t, false, doc, "t1")
checkMatch(t, true, doc, "")
checkMatch(t, false, doc, "")
checkMatch(t, true, doc, "")
checkMatch(t, false, doc, "")

// Also, check that anchors exist (only) for exported symbols.
// exported:
checkMatch(t, true, doc, "<a id='V1'")
checkMatch(t, true, doc, "<a id='C1'")
checkMatch(t, true, doc, "<h3 id='T1'")
checkMatch(t, true, doc, "<h3 id='F1'")
checkMatch(t, true, doc, "<h4 id='T1.M1'")
checkMatch(t, true, doc, "<a id=''")
checkMatch(t, true, doc, "<a id=''")
checkMatch(t, true, doc, "<h3 id=''")
checkMatch(t, true, doc, "<h3 id=''")
checkMatch(t, true, doc, "<h4 id='Tπ.Mπ'")
// unexported:
checkMatch(t, false, doc, "<a id='v1'")
checkMatch(t, false, doc, "<a id='c1'")
checkMatch(t, false, doc, "<h3 id='t1'")
checkMatch(t, false, doc, "<h3 id='f1'")
checkMatch(t, false, doc, "<h4 id='T1.m1'")
checkMatch(t, false, doc, "<h4 id='t1.M1'")
checkMatch(t, false, doc, "<h4 id='t1.m1'")
checkMatch(t, false, doc, "<a id=''")
checkMatch(t, false, doc, "<a id=''")
checkMatch(t, false, doc, "<h3 id=''")
checkMatch(t, false, doc, "<h3 id=''")
checkMatch(t, false, doc, "<h4 id='Tπ.mπ'")
checkMatch(t, false, doc, "<h4 id='tπ.Mπ'")
checkMatch(t, false, doc, "<h4 id='tπ.mπ'")
})
}

Expand Down

0 comments on commit 951bb40

Please sign in to comment.