This file is indexed.

/usr/share/gocode/src/github.com/hanwen/go-fuse/unionfs/timedcache_test.go is in golang-github-hanwen-go-fuse-dev 0.0~git20171124.0.14c3015-4.

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
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package unionfs

import (
	"testing"
	"time"
)

func TestTimedCacheUncacheable(t *testing.T) {
	fetchCount := 0
	fetch := func(n string) (interface{}, bool) {
		fetchCount++
		i := int(n[0])
		return &i, false
	}

	cache := NewTimedCache(fetch, 0)
	v := cache.Get("n").(*int)
	w := cache.Get("n").(*int)
	if *v != int('n') || *w != *v {
		t.Errorf("value mismatch: got %d, %d want %d", *v, *w, int('n'))
	}

	if fetchCount != 2 {
		t.Fatalf("Should have fetched twice: %d", fetchCount)
	}
}

func TestTimedCache(t *testing.T) {
	fetchCount := 0
	fetch := func(n string) (interface{}, bool) {
		fetchCount++
		i := int(n[0])
		return &i, true
	}

	// This fails with 1e6 on some Opteron CPUs.
	ttl := 100 * time.Millisecond

	cache := NewTimedCache(fetch, ttl)
	v := cache.Get("n").(*int)
	if *v != int('n') {
		t.Errorf("value mismatch: got %d, want %d", *v, int('n'))
	}
	if fetchCount != 1 {
		t.Errorf("fetch count mismatch: got %d want 1", fetchCount)
	}

	// The cache update is async.
	time.Sleep(time.Duration(ttl / 10))

	w := cache.Get("n")
	if v != w {
		t.Errorf("Huh, inconsistent: 1st = %v != 2nd = %v", v, w)
	}

	if fetchCount > 1 {
		t.Errorf("fetch count fail: %d > 1", fetchCount)
	}

	time.Sleep(time.Duration(ttl * 2))
	cache.Purge()

	w = cache.Get("n")
	if fetchCount == 1 {
		t.Error("Did not fetch again. Purge unsuccessful?")
	}
}