@@ -2,11 +2,9 @@ package kubernetes
22
33import (
44 "fmt"
5- "math/rand"
65 "os"
76 "sync"
87 "testing"
9- "time"
108
119 "github.com/hashicorp/terraform/backend"
1210 "github.com/hashicorp/terraform/state"
@@ -77,8 +75,8 @@ func TestBackendLocksSoak(t *testing.T) {
7775 testACC (t )
7876 defer cleanupK8sResources (t )
7977
80- clientCount := 1000
81- lockCount := 0
78+ clientCount := 100
79+ lockAttempts := 100
8280
8381 lockers := []statemgr.Locker {}
8482 for i := 0 ; i < clientCount ; i ++ {
@@ -97,30 +95,28 @@ func TestBackendLocksSoak(t *testing.T) {
9795 wg := sync.WaitGroup {}
9896 for i , l := range lockers {
9997 wg .Add (1 )
100- go func (locker statemgr.Locker , i int ) {
101- r := rand . Intn ( 10 )
102- time . Sleep ( time . Duration ( r ) * time . Microsecond )
98+ go func (locker statemgr.Locker , n int ) {
99+ defer wg . Done ( )
100+
103101 li := state .NewLockInfo ()
104102 li .Operation = "test"
105- li .Who = fmt .Sprintf ("client-%v" , i )
106- _ , err := locker .Lock (li )
107- if err == nil {
108- t .Logf ("[INFO] Client %v got the lock\r \n " , i )
109- lockCount ++
103+ li .Who = fmt .Sprintf ("client-%v" , n )
104+
105+ for i := 0 ; i < lockAttempts ; i ++ {
106+ id , err := locker .Lock (li )
107+ if err != nil {
108+ continue
109+ }
110+
111+ err = locker .Unlock (id )
112+ if err != nil {
113+ t .Errorf ("failed to unlock: %v" , err )
114+ }
110115 }
111- wg .Done ()
112116 }(l , i )
113117 }
114118
115119 wg .Wait ()
116-
117- if lockCount > 1 {
118- t .Fatalf ("multiple backend clients were able to acquire a lock, count: %v" , lockCount )
119- }
120-
121- if lockCount == 0 {
122- t .Fatal ("no clients were able to acquire a lock" )
123- }
124120}
125121
126122func cleanupK8sResources (t * testing.T ) {
0 commit comments