@@ -26,9 +26,11 @@ import (
26
26
"reflect"
27
27
"strings"
28
28
"testing"
29
+ "time"
29
30
30
31
"k8s.io/apimachinery/pkg/util/sets"
31
32
utilversion "k8s.io/apimachinery/pkg/util/version"
33
+ "k8s.io/apimachinery/pkg/util/wait"
32
34
"k8s.io/utils/exec"
33
35
fakeexec "k8s.io/utils/exec/testing"
34
36
)
@@ -1109,11 +1111,23 @@ func TestRestoreAllGrabOldLock(t *testing.T) {
1109
1111
runner := newInternal (& fexec , ProtocolIPv4 , TestLockfilePath )
1110
1112
defer os .Remove (TestLockfilePath )
1111
1113
1112
- // Grab the abstract @xtables socket
1113
- runLock , err := net .ListenUnix ("unix" , & net.UnixAddr {Name : "@xtables" , Net : "unix" })
1114
+ var runLock * net.UnixListener
1115
+ // Grab the abstract @xtables socket, will retry if the socket exists
1116
+ err := wait .PollImmediate (time .Second , wait .ForeverTestTimeout , func () (done bool , err error ) {
1117
+ runLock , err = net .ListenUnix ("unix" , & net.UnixAddr {Name : "@xtables" , Net : "unix" })
1118
+ if err != nil {
1119
+ t .Logf ("Failed to lock @xtables: %v, will retry." , err )
1120
+ return false , nil
1121
+ }
1122
+ return true , nil
1123
+ })
1114
1124
if err != nil {
1115
- t .Fatalf ("expected to lock @xtables, got %v" , err )
1125
+ t .Fatal ("Timed out locking @xtables" )
1126
+ }
1127
+ if runLock == nil {
1128
+ t .Fatal ("Unexpected nil runLock" )
1116
1129
}
1130
+
1117
1131
defer runLock .Close ()
1118
1132
1119
1133
err = runner .RestoreAll ([]byte {}, NoFlushTables , RestoreCounters )
0 commit comments