You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
//go:build libvirt
|
|
|
|
package hypervisor
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestStorageConfigurationLockFailsFastAndReleases(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "storage-config.lock")
|
|
release, err := acquireStorageConfigurationLock(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
secondRelease, err := acquireStorageConfigurationLock(path)
|
|
if err == nil {
|
|
secondRelease()
|
|
release()
|
|
t.Fatal("concurrent storage configuration acquired the host lock")
|
|
}
|
|
var public interface{ PublicCode() string }
|
|
if !errors.As(err, &public) || public.PublicCode() != "storage_configuration_busy" {
|
|
release()
|
|
t.Fatalf("concurrent lock error = %v", err)
|
|
}
|
|
wrapped := storageConfigurationNotApplied(err)
|
|
var semantics interface{ FailureSemantics() (bool, bool) }
|
|
if !errors.As(wrapped, &semantics) {
|
|
release()
|
|
t.Fatal("pre-mutation storage failure did not expose failure semantics")
|
|
}
|
|
effect, safe := semantics.FailureSemantics()
|
|
if effect || !safe {
|
|
release()
|
|
t.Fatalf("pre-mutation storage failure semantics = effect:%v safe:%v", effect, safe)
|
|
}
|
|
|
|
release()
|
|
thirdRelease, err := acquireStorageConfigurationLock(path)
|
|
if err != nil {
|
|
t.Fatalf("storage configuration lock remained held after release: %v", err)
|
|
}
|
|
thirdRelease()
|
|
}
|
|
|
|
func TestStorageConfigurationLockRejectsInvalidPath(t *testing.T) {
|
|
if _, err := acquireStorageConfigurationLock("relative.lock"); err == nil {
|
|
t.Fatal("relative storage configuration lock path was accepted")
|
|
}
|
|
}
|