@@ -21,7 +21,6 @@ import (
2121 "testing"
2222 "time"
2323
24- "github.com/stretchr/testify/assert"
2524 "github.com/stretchr/testify/require"
2625 "go.uber.org/goleak"
2726
@@ -33,6 +32,7 @@ import (
3332 corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
3433 tenancyv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1"
3534 kcpclientset "github.com/kcp-dev/kcp/sdk/client/clientset/versioned/cluster"
35+ kcptestinghelpers "github.com/kcp-dev/kcp/sdk/testing/helpers"
3636 "github.com/kcp-dev/kcp/test/integration/framework"
3737)
3838
@@ -57,23 +57,31 @@ func createAndDeleteWs(ctx context.Context, t *testing.T, kcpClient kcpclientset
5757 require .NoError (t , err , "failed to create workspace %q" , workspace .Name )
5858
5959 t .Logf ("Wait until the %q workspace is ready" , workspace .Name )
60- require .Eventually (t , func () bool {
60+ kcptestinghelpers .Eventually (t , func () ( bool , string ) {
6161 workspace , err := kcpClient .Cluster (core .RootCluster .Path ()).TenancyV1alpha1 ().Workspaces ().Get (ctx , workspace .Name , metav1.GetOptions {})
62- require .NoError (t , err , "failed to get workspace" )
63- if actual , expected := workspace .Status .Phase , corev1alpha1 .LogicalClusterPhaseReady ; actual != expected {
64- return false
62+ if err != nil {
63+ return false , err .Error ()
6564 }
66- return workspace .Status .Phase == corev1alpha1 .LogicalClusterPhaseReady
67- }, 1 * time .Minute , 100 * time .Millisecond )
65+ if phase := workspace .Status .Phase ; phase != corev1alpha1 .LogicalClusterPhaseReady {
66+ return false , "workspace is not ready, is " + string (phase )
67+ }
68+ return true , ""
69+ }, wait .ForeverTestTimeout , 100 * time .Millisecond )
6870
6971 t .Logf ("Delete workspace %q" , workspace .Name )
7072 err = kcpClient .Cluster (core .RootCluster .Path ()).TenancyV1alpha1 ().Workspaces ().Delete (ctx , workspace .Name , metav1.DeleteOptions {})
7173 require .NoError (t , err , "failed to delete workspace %s" , workspace .Name )
7274
7375 t .Logf ("Ensure workspace %q is removed" , workspace .Name )
74- require .Eventually (t , func () bool {
75- _ , err := kcpClient .Cluster (core .RootCluster .Path ()).TenancyV1alpha1 ().Workspaces ().Get (ctx , workspace .Name , metav1.GetOptions {})
76- return apierrors .IsNotFound (err )
76+ kcptestinghelpers .Eventually (t , func () (bool , string ) {
77+ ws , err := kcpClient .Cluster (core .RootCluster .Path ()).TenancyV1alpha1 ().Workspaces ().Get (ctx , workspace .Name , metav1.GetOptions {})
78+ if err != nil {
79+ if apierrors .IsNotFound (err ) {
80+ return true , ""
81+ }
82+ return false , err .Error ()
83+ }
84+ return ws == nil , ""
7785 }, wait .ForeverTestTimeout , 100 * time .Millisecond )
7886
7987 // See https://github.com/kcp-dev/kcp/issues/3488
@@ -96,9 +104,10 @@ func TestWorkspaceDeletionLeak(t *testing.T) {
96104 createAndDeleteWs (ctx , t , kcpClient , "leak-test" )
97105
98106 t .Logf ("Check for leftover goroutines" )
99- require . EventuallyWithT (t , func (collect * assert. CollectT ) {
107+ kcptestinghelpers . Eventually (t , func () ( bool , string ) {
100108 if err := goleak .Find (curGoroutines ); err != nil {
101- collect . Errorf ( "found leaking goroutines: %#v" , err )
109+ return false , err . Error ( )
102110 }
103- }, wait .ForeverTestTimeout , time .Millisecond * 100 , "eventually there will be no random goroutines running while checking for leaks" )
111+ return true , ""
112+ }, wait .ForeverTestTimeout , 100 * time .Millisecond )
104113}
0 commit comments