@@ -40,7 +40,10 @@ import (
40
40
func TestWatchBasedManager (t * testing.T ) {
41
41
testNamespace := "test-watch-based-manager"
42
42
server := kubeapiservertesting .StartTestServerOrDie (t , nil , framework .DefaultTestServerFlags (), framework .SharedEtcd ())
43
- defer server .TearDownFn ()
43
+ t .Cleanup (server .TearDownFn )
44
+
45
+ ctx , cancel := context .WithCancel (context .Background ())
46
+ t .Cleanup (cancel )
44
47
45
48
const n = 10
46
49
server .ClientConfig .QPS = 10000
@@ -49,15 +52,15 @@ func TestWatchBasedManager(t *testing.T) {
49
52
if err != nil {
50
53
t .Fatalf ("unexpected error: %v" , err )
51
54
}
52
- if _ , err := client .CoreV1 ().Namespaces ().Create (context . TODO () , (& v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : testNamespace }}), metav1.CreateOptions {}); err != nil {
55
+ if _ , err := client .CoreV1 ().Namespaces ().Create (ctx , (& v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : testNamespace }}), metav1.CreateOptions {}); err != nil {
53
56
t .Fatal (err )
54
57
}
55
58
56
59
listObj := func (namespace string , options metav1.ListOptions ) (runtime.Object , error ) {
57
- return client .CoreV1 ().Secrets (namespace ).List (context . TODO () , options )
60
+ return client .CoreV1 ().Secrets (namespace ).List (ctx , options )
58
61
}
59
62
watchObj := func (namespace string , options metav1.ListOptions ) (watch.Interface , error ) {
60
- return client .CoreV1 ().Secrets (namespace ).Watch (context . TODO () , options )
63
+ return client .CoreV1 ().Secrets (namespace ).Watch (ctx , options )
61
64
}
62
65
newObj := func () runtime.Object { return & v1.Secret {} }
63
66
// We want all watches to be up and running to stress test it.
@@ -66,7 +69,8 @@ func TestWatchBasedManager(t *testing.T) {
66
69
fakeClock := testingclock .NewFakeClock (time .Now ())
67
70
68
71
stopCh := make (chan struct {})
69
- defer close (stopCh )
72
+ t .Cleanup (func () { close (stopCh ) })
73
+
70
74
store := manager .NewObjectCache (listObj , watchObj , newObj , isImmutable , schema.GroupResource {Group : "v1" , Resource : "secrets" }, fakeClock , time .Minute , stopCh )
71
75
72
76
// create 1000 secrets in parallel
@@ -79,7 +83,7 @@ func TestWatchBasedManager(t *testing.T) {
79
83
defer wg .Done ()
80
84
for j := 0 ; j < 100 ; j ++ {
81
85
name := fmt .Sprintf ("s%d" , i * 100 + j )
82
- if _ , err := client .CoreV1 ().Secrets (testNamespace ).Create (context . TODO () , & v1.Secret {ObjectMeta : metav1.ObjectMeta {Name : name }}, metav1.CreateOptions {}); err != nil {
86
+ if _ , err := client .CoreV1 ().Secrets (testNamespace ).Create (ctx , & v1.Secret {ObjectMeta : metav1.ObjectMeta {Name : name }}, metav1.CreateOptions {}); err != nil {
83
87
select {
84
88
case errCh <- err :
85
89
default :
0 commit comments