SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix: close volumes and EC shards in tests for Windows compatibility (#8152)
Ping Qiu5c8de5e28296
diff --git a/weed/storage/disk_location_ec_test.go b/weed/storage/disk_location_ec_test.goindex 23b7d8c408..e40870b7ff 100644--- a/weed/storage/disk_location_ec_test.go+++ b/weed/storage/disk_location_ec_test.go@@ -11,6 +11,13 @@ import ("github.com/seaweedfs/seaweedfs/weed/util")+// closeEcVolumes closes all EC volumes in the given DiskLocation to release file handles.+func closeEcVolumes(dl *DiskLocation) {+ for _, ecVol := range dl.ecVolumes {+ ecVol.Close()+ }+}+// TestIncompleteEcEncodingCleanup tests the cleanup logic for incomplete EC encoding scenariosfunc TestIncompleteEcEncodingCleanup(t *testing.T) {tests := []struct {@@ -182,11 +189,18 @@ func TestIncompleteEcEncodingCleanup(t *testing.T) {t.Logf("loadAllEcShards returned error (expected in some cases): %v", loadErr)}+ // Close EC volumes before idempotency test to avoid leaking file handles+ closeEcVolumes(diskLocation)+ diskLocation.ecVolumes = make(map[needle.VolumeId]*erasure_coding.EcVolume)+// Test idempotency - running again should not cause issuesloadErr2 := diskLocation.loadAllEcShards(nil)if loadErr2 != nil {t.Logf("Second loadAllEcShards returned error: %v", loadErr2)}+ t.Cleanup(func() {+ closeEcVolumes(diskLocation)+ })// Verify cleanup expectationsif tt.expectCleanup {@@ -554,6 +568,9 @@ func TestEcCleanupWithSeparateIdxDirectory(t *testing.T) {if loadErr != nil {t.Logf("loadAllEcShards error: %v", loadErr)}+ t.Cleanup(func() {+ closeEcVolumes(diskLocation)+ })// Verify cleanup occurred in data directory (shards)for i := 0; i < erasure_coding.TotalShardsCount; i++ {@@ -625,6 +642,9 @@ func TestDistributedEcVolumeNoFileDeletion(t *testing.T) {if loadErr != nil {t.Logf("loadAllEcShards returned error (expected): %v", loadErr)}+ t.Cleanup(func() {+ closeEcVolumes(diskLocation)+ })// CRITICAL CHECK: Verify shard files still exist (should NOT be deleted)for i := 0; i < 5; i++ {diff --git a/weed/storage/idx_binary_search_test.go b/weed/storage/idx_binary_search_test.goindex e04185bcd3..77d38e562a 100644--- a/weed/storage/idx_binary_search_test.go+++ b/weed/storage/idx_binary_search_test.go@@ -18,6 +18,7 @@ func TestFirstInvalidIndex(t *testing.T) {if err != nil {t.Fatalf("volume creation: %v", err)}+ defer v.Close()type WriteInfo struct {offset int64size int32diff --git a/weed/storage/store_load_balancing_test.go b/weed/storage/store_load_balancing_test.goindex 35475a6ae0..a16d1474d5 100644--- a/weed/storage/store_load_balancing_test.go+++ b/weed/storage/store_load_balancing_test.go@@ -45,7 +45,10 @@ func newTestStore(t *testing.T, numDirs int) *Store {}}}()- t.Cleanup(func() { close(done) })+ t.Cleanup(func() {+ store.Close()+ close(done)+ })return store}diff --git a/weed/storage/volume_read_test.go b/weed/storage/volume_read_test.goindex efedadc310..d3fb31c64b 100644--- a/weed/storage/volume_read_test.go+++ b/weed/storage/volume_read_test.go@@ -16,6 +16,7 @@ func TestReadNeedMetaWithWritesAndUpdates(t *testing.T) {if err != nil {t.Fatalf("volume creation: %v", err)}+ defer v.Close()type WriteInfo struct {offset int64size int32@@ -55,6 +56,7 @@ func TestReadNeedMetaWithDeletesThenWrites(t *testing.T) {if err != nil {t.Fatalf("volume creation: %v", err)}+ defer v.Close()type WriteInfo struct {offset int64size int32diff --git a/weed/storage/volume_vacuum_test.go b/weed/storage/volume_vacuum_test.goindex 29b990f70e..9022fc5c7f 100644--- a/weed/storage/volume_vacuum_test.go+++ b/weed/storage/volume_vacuum_test.go@@ -119,6 +119,7 @@ func testCompaction(t *testing.T, needleMapKind NeedleMapKind) {if err != nil {t.Fatalf("volume reloading: %v", err)}+ defer v.Close()for i := 1; i <= beforeCommitFileCount+afterCommitFileCount; i++ {diff --git a/weed/storage/volume_write_test.go b/weed/storage/volume_write_test.goindex ce7c184bd0..f3e8ebe01c 100644--- a/weed/storage/volume_write_test.go+++ b/weed/storage/volume_write_test.go@@ -21,6 +21,7 @@ func TestSearchVolumesWithDeletedNeedles(t *testing.T) {if err != nil {t.Fatalf("volume creation: %v", err)}+ defer v.Close()count := 20@@ -119,6 +120,7 @@ func TestDestroyNonemptyVolumeWithOnlyEmpty(t *testing.T) {if err != nil {t.Fatalf("volume creation: %v", err)}+ defer v.Close()path := v.DataBackend.Name()// should return "volume not empty" error and do not delete file when Destroy non-empty volume