-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crl provider: Static and FileWatcher provider implementations #6670
Changes from 2 commits
978cb44
7d032e0
cdbc298
95991d8
32e3158
00de36e
8033cab
338a7f4
d1f63fe
01afa97
401eb79
c88d12d
1feaae3
a9a84f1
5a0acad
f3c830b
4ea1b34
aeebd4e
735ac20
5c76a60
0bc7757
f844c8c
a4da85e
c3ba07e
ffe5c34
6d28181
7814373
1a46b65
d7f1555
2f1935d
0a7b086
8d05f28
ccbf7f6
99ecab0
9e5a70d
5643760
8898959
b16af8b
21f4301
51b42aa
f0c1ca4
08188d1
9b8d07e
ad15e23
8e02546
e6a690d
340757d
1e4c5ac
f654d18
53d6b05
1f398eb
f3dcca1
131e6e7
bc14ea8
96bf905
0ce6a2c
c57a08a
4c53c56
7fedab5
1025333
d9ba363
150e585
d7cf48f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
"io" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -137,9 +138,13 @@ func (s) TestFileWatcherCRLProviderConfig(t *testing.T) { | |
// that it’s correctly processed. Additionally, we also check if number of | ||
// invocations of custom callback is correct. | ||
func (s) TestFileWatcherCRLProvider(t *testing.T) { | ||
t.Parallel() | ||
const nonCRLFilesUnderCRLDirectory = 5 | ||
nonCRLFilesSet := make(map[string]struct{}) | ||
var nonCRLMutex sync.Mutex | ||
customCallback := func(err error) { | ||
nonCRLMutex.Lock() | ||
defer nonCRLMutex.Unlock() | ||
nonCRLFilesSet[err.Error()] = struct{}{} | ||
} | ||
p, err := NewFileWatcherCRLProvider(FileWatcherOptions{ | ||
|
@@ -191,10 +196,11 @@ func (s) TestFileWatcherCRLProvider(t *testing.T) { | |
} | ||
}) | ||
} | ||
p.Close() | ||
if len(nonCRLFilesSet) < nonCRLFilesUnderCRLDirectory { | ||
t.Fatalf("Number of callback executions: got %v, want %v", len(nonCRLFilesSet), nonCRLFilesUnderCRLDirectory) | ||
} | ||
p.Close() | ||
|
||
} | ||
|
||
// TestFileWatcherCRLProviderDirectoryScan tests how FileWatcherCRLProvider | ||
|
@@ -258,6 +264,8 @@ func (s) TestFileWatcherCRLProviderDirectoryScan(t *testing.T) { | |
t.Run(tt.desc, func(t *testing.T) { | ||
copyFiles(sourcePath, targetPath, tt.fileNames, t) | ||
p.ScanCRLDirectory() | ||
p.scanMutex.Lock() | ||
defer p.scanMutex.Unlock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything similar here? We really shouldn't need mutexes while testing conditions, or else they might be flaky if we lose a race. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I'm not sure - I need the same instance of Provider for all the table tests, and I need to make the check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see, you're taking the mutex from the thing you're testing. Can you call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's doable - I can provide a list of filenames to be scanned ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, This is OK, then, though I'd prefer stricter validation, i.e. checking the contents of the map, or at least the keys, and not just the length. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did the refactoring to the stricter validation and I think it looks better now (plus no more calling mutexes inside tests) |
||
if diff := cmp.Diff(len(p.crls), tt.expectedEntries); diff != "" { | ||
t.Errorf("Expected number of entries in the map do not match\ndiff (-got +want):\n%s", diff) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So can you delete this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there is no need to protect this local to the test map anymore. We do the read once provider's goroutine is done