mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
backend/remote-state/oss: Add test revealing bug in state locking
This commit is contained in:
parent
07139e453a
commit
1f3a2c0e02
@ -85,6 +85,52 @@ func TestRemoteClientLocks(t *testing.T) {
|
|||||||
remote.TestRemoteLocks(t, s1.(*remote.State).Client, s2.(*remote.State).Client)
|
remote.TestRemoteLocks(t, s1.(*remote.State).Client, s2.(*remote.State).Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// verify that the backend can handle more than one state in the same table
|
||||||
|
func TestRemoteClientLocks_multipleStates(t *testing.T) {
|
||||||
|
testACC(t)
|
||||||
|
bucketName := fmt.Sprintf("tf-remote-oss-test-force-%x", time.Now().Unix())
|
||||||
|
tableName := fmt.Sprintf("tfRemoteTestForce%x", time.Now().Unix())
|
||||||
|
path := "testState"
|
||||||
|
|
||||||
|
b1 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
|
||||||
|
"bucket": bucketName,
|
||||||
|
"prefix": path,
|
||||||
|
"encrypt": true,
|
||||||
|
"tablestore_table": tableName,
|
||||||
|
"tablestore_endpoint": RemoteTestUsedOTSEndpoint,
|
||||||
|
})).(*Backend)
|
||||||
|
|
||||||
|
b2 := backend.TestBackendConfig(t, New(), backend.TestWrapConfig(map[string]interface{}{
|
||||||
|
"bucket": bucketName,
|
||||||
|
"prefix": path,
|
||||||
|
"encrypt": true,
|
||||||
|
"tablestore_table": tableName,
|
||||||
|
"tablestore_endpoint": RemoteTestUsedOTSEndpoint,
|
||||||
|
})).(*Backend)
|
||||||
|
|
||||||
|
createOSSBucket(t, b1.ossClient, bucketName)
|
||||||
|
defer deleteOSSBucket(t, b1.ossClient, bucketName)
|
||||||
|
createTablestoreTable(t, b1.otsClient, tableName)
|
||||||
|
defer deleteTablestoreTable(t, b1.otsClient, tableName)
|
||||||
|
|
||||||
|
s1, err := b1.StateMgr("s1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s1.Lock(state.NewLockInfo()); err != nil {
|
||||||
|
t.Fatal("failed to get lock for s1:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// s1 is now locked, s2 should not be locked as it's a different state file
|
||||||
|
s2, err := b2.StateMgr("s2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s2.Lock(state.NewLockInfo()); err != nil {
|
||||||
|
t.Fatal("failed to get lock for s2:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// verify that we can unlock a state with an existing lock
|
// verify that we can unlock a state with an existing lock
|
||||||
func TestRemoteForceUnlock(t *testing.T) {
|
func TestRemoteForceUnlock(t *testing.T) {
|
||||||
testACC(t)
|
testACC(t)
|
||||||
|
Loading…
Reference in New Issue
Block a user