This file is indexed.

/usr/share/gocode/src/github.com/coreos/go-oidc/oidc/client_race_test.go is in golang-github-coreos-go-oidc-dev 0.0~git20160926.0.16c5ecc-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// This file contains tests which depend on the race detector being enabled.
// +build race

package oidc

import (
	"encoding/json"
	"net/http"
	"net/http/httptest"
	"net/url"
	"testing"
	"time"
)

type testProvider struct {
	baseURL *url.URL
}

func (p *testProvider) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != discoveryConfigPath {
		http.NotFound(w, r)
		return
	}

	cfg := ProviderConfig{
		Issuer:    p.baseURL,
		ExpiresAt: time.Now().Add(time.Second),
	}
	cfg = fillRequiredProviderFields(cfg)
	json.NewEncoder(w).Encode(&cfg)
}

// This test fails by triggering the race detector, not by calling t.Error or t.Fatal.
func TestProviderSyncRace(t *testing.T) {

	prov := &testProvider{}

	s := httptest.NewServer(prov)
	defer s.Close()
	u, err := url.Parse(s.URL)
	if err != nil {
		t.Fatal(err)
	}
	prov.baseURL = u

	prevValue := minimumProviderConfigSyncInterval
	defer func() { minimumProviderConfigSyncInterval = prevValue }()

	// Reduce the sync interval to increase the write frequencey.
	minimumProviderConfigSyncInterval = 5 * time.Millisecond

	cliCfg := ClientConfig{
		HTTPClient: http.DefaultClient,
	}
	cli, err := NewClient(cliCfg)
	if err != nil {
		t.Error(err)
		return
	}

	if !cli.providerConfig.Get().Empty() {
		t.Errorf("want c.ProviderConfig == nil, got c.ProviderConfig=%#v")
	}

	// SyncProviderConfig beings a goroutine which writes to the client's provider config.
	c := cli.SyncProviderConfig(s.URL)
	if cli.providerConfig.Get().Empty() {
		t.Errorf("want c.ProviderConfig != nil")
	}

	defer func() {
		// stop the background process
		c <- struct{}{}
	}()

	for i := 0; i < 10; i++ {
		time.Sleep(5 * time.Millisecond)
		// Creating an OAuth client reads from the provider config.
		cli.OAuthClient()
	}
}