-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathcache_test.go
More file actions
57 lines (50 loc) · 1.23 KB
/
Copy pathcache_test.go
File metadata and controls
57 lines (50 loc) · 1.23 KB
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
// Copyright 2022-2026 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package libopenapi
import (
"os"
"sync"
"testing"
"github.com/pb33f/testify/assert"
"github.com/pb33f/testify/require"
)
func TestClearAllCaches(t *testing.T) {
// ClearAllCaches should not panic when called on empty caches.
ClearAllCaches()
// Call twice to ensure idempotency.
ClearAllCaches()
}
// ClearAllCaches must be safe to call while other goroutines build and compare documents (run with -race).
func TestClearAllCaches_ConcurrentWithDocumentWork(t *testing.T) {
original, err := os.ReadFile("test_specs/burgershop.openapi.yaml")
require.NoError(t, err)
modified, err := os.ReadFile("test_specs/burgershop.openapi-modified.yaml")
require.NoError(t, err)
var wg sync.WaitGroup
for w := 0; w < 4; w++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 3; i++ {
left, _ := NewDocument(original)
right, _ := NewDocument(modified)
changes, errs := CompareDocuments(left, right)
assert.Empty(t, errs)
assert.NotNil(t, changes)
}
}()
}
done := make(chan struct{})
go func() {
wg.Wait()
close(done)
}()
for {
select {
case <-done:
return
default:
ClearAllCaches()
}
}
}