github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/fs/setup_teardown_test.go (about) 1 package fs 2 3 import ( 4 "io/ioutil" 5 "os" 6 "runtime" 7 "sync" 8 "syscall" 9 "testing" 10 11 "golang.org/x/sys/unix" 12 13 "github.com/swiftstack/ProxyFS/conf" 14 "github.com/swiftstack/ProxyFS/ramswift" 15 "github.com/swiftstack/ProxyFS/transitions" 16 ) 17 18 var ( 19 testConfMap conf.ConfMap 20 testRamswiftDoneChan chan bool // our test chan used during testTeardown() to know ramswift is, indeed, down 21 testVolumeStruct *volumeStruct // our global volumeStruct to be used in tests 22 ) 23 24 func testSetup(t *testing.T, starvationMode bool) { 25 var ( 26 err error 27 ok bool 28 signalHandlerIsArmedWG sync.WaitGroup 29 testConfMapStrings []string 30 testConfUpdateStrings []string 31 testDir string 32 testVolumeHandle VolumeHandle 33 ) 34 35 testDir, err = ioutil.TempDir(os.TempDir(), "ProxyFS_test_fs_") 36 if nil != err { 37 t.Fatalf("ioutil.TempDir() failed: %v", err) 38 } 39 40 err = os.Chdir(testDir) 41 if nil != err { 42 t.Fatalf("os.Chdir() failed: %v", err) 43 } 44 45 err = os.Mkdir("TestVolume", os.ModePerm) 46 47 testConfMapStrings = []string{ 48 "Stats.IPAddr=localhost", 49 "Stats.UDPPort=52184", 50 "Stats.BufferLength=100", 51 "Stats.MaxLatency=1s", 52 "Logging.LogFilePath=/dev/null", 53 "Logging.LogToConsole=false", 54 "SwiftClient.NoAuthIPAddr=127.0.0.1", 55 "SwiftClient.NoAuthTCPPort=35262", 56 "SwiftClient.Timeout=10s", 57 "SwiftClient.RetryLimit=3", 58 "SwiftClient.RetryLimitObject=3", 59 "SwiftClient.RetryDelay=10ms", 60 "SwiftClient.RetryDelayObject=10ms", 61 "SwiftClient.RetryExpBackoff=1.2", 62 "SwiftClient.RetryExpBackoffObject=2.0", 63 "PhysicalContainerLayout:PhysicalContainerLayoutReplicated3Way.ContainerStoragePolicy=silver", 64 "PhysicalContainerLayout:PhysicalContainerLayoutReplicated3Way.ContainerNamePrefix=Replicated3Way_", 65 "PhysicalContainerLayout:PhysicalContainerLayoutReplicated3Way.ContainersPerPeer=10", 66 "PhysicalContainerLayout:PhysicalContainerLayoutReplicated3Way.MaxObjectsPerContainer=1000000", 67 "Peer:Peer0.PublicIPAddr=127.0.0.1", 68 "Peer:Peer0.PrivateIPAddr=127.0.0.1", 69 "Peer:Peer0.ReadCacheQuotaFraction=0.20", 70 "Cluster.Peers=Peer0", 71 "Cluster.WhoAmI=Peer0", 72 "Volume:TestVolume.FSID=1", 73 "Volume:TestVolume.PrimaryPeer=Peer0", 74 "Volume:TestVolume.AccountName=AUTH_test", 75 "Volume:TestVolume.AutoFormat=true", 76 "Volume:TestVolume.CheckpointContainerName=.__checkpoint__", 77 "Volume:TestVolume.CheckpointContainerStoragePolicy=gold", 78 "Volume:TestVolume.CheckpointInterval=10s", 79 "Volume:TestVolume.DefaultPhysicalContainerLayout=PhysicalContainerLayoutReplicated3Way", 80 "Volume:TestVolume.MaxFlushSize=10485760", 81 "Volume:TestVolume.MaxFlushTime=10s", 82 "Volume:TestVolume.FileDefragmentChunkSize=10485760", 83 "Volume:TestVolume.FileDefragmentChunkDelay=10ms", 84 "Volume:TestVolume.NonceValuesToReserve=100", 85 "Volume:TestVolume.MaxEntriesPerDirNode=32", 86 "Volume:TestVolume.MaxExtentsPerFileNode=32", 87 "Volume:TestVolume.MaxInodesPerMetadataNode=32", 88 "Volume:TestVolume.MaxLogSegmentsPerMetadataNode=64", 89 "Volume:TestVolume.MaxDirFileNodesPerMetadataNode=16", 90 "Volume:TestVolume.MaxBytesInodeCache=100000", 91 "Volume:TestVolume.InodeCacheEvictInterval=1s", 92 "Volume:TestVolume.ActiveLeaseEvictLowLimit=5000", 93 "Volume:TestVolume.ActiveLeaseEvictHighLimit=5010", 94 "VolumeGroup:TestVolumeGroup.VolumeList=TestVolume", 95 "VolumeGroup:TestVolumeGroup.VirtualIPAddr=", 96 "VolumeGroup:TestVolumeGroup.PrimaryPeer=Peer0", 97 "VolumeGroup:TestVolumeGroup.ReadCacheLineSize=1000000", 98 "VolumeGroup:TestVolumeGroup.ReadCacheWeight=100", 99 "FSGlobals.VolumeGroupList=TestVolumeGroup", 100 "FSGlobals.CheckpointHeaderConsensusAttempts=5", 101 "FSGlobals.MountRetryLimit=6", 102 "FSGlobals.MountRetryDelay=1s", 103 "FSGlobals.MountRetryExpBackoff=2", 104 "FSGlobals.LogCheckpointHeaderPosts=true", 105 "FSGlobals.TryLockBackoffMin=10ms", 106 "FSGlobals.TryLockBackoffMax=50ms", 107 "FSGlobals.TryLockSerializationThreshhold=5", 108 "FSGlobals.SymlinkMax=32", 109 "FSGlobals.CoalesceElementChunkSize=16", 110 "FSGlobals.InodeRecCacheEvictLowLimit=10000", 111 "FSGlobals.InodeRecCacheEvictHighLimit=10010", 112 "FSGlobals.LogSegmentRecCacheEvictLowLimit=10000", 113 "FSGlobals.LogSegmentRecCacheEvictHighLimit=10010", 114 "FSGlobals.BPlusTreeObjectCacheEvictLowLimit=10000", 115 "FSGlobals.BPlusTreeObjectCacheEvictHighLimit=10010", 116 "FSGlobals.DirEntryCacheEvictLowLimit=10000", 117 "FSGlobals.DirEntryCacheEvictHighLimit=10010", 118 "FSGlobals.FileExtentMapEvictLowLimit=10000", 119 "FSGlobals.FileExtentMapEvictHighLimit=10010", 120 "FSGlobals.EtcdEnabled=false", 121 "RamSwiftInfo.MaxAccountNameLength=256", 122 "RamSwiftInfo.MaxContainerNameLength=256", 123 "RamSwiftInfo.MaxObjectNameLength=1024", 124 "RamSwiftInfo.AccountListingLimit=10000", 125 "RamSwiftInfo.ContainerListingLimit=10000", 126 } 127 128 testConfMap, err = conf.MakeConfMapFromStrings(testConfMapStrings) 129 if nil != err { 130 t.Fatalf("conf.MakeConfMapFromStrings() failed: %v", err) 131 } 132 133 if starvationMode { 134 testConfUpdateStrings = []string{ 135 "SwiftClient.ChunkedConnectionPoolSize=1", 136 "SwiftClient.NonChunkedConnectionPoolSize=1", 137 } 138 } else { 139 testConfUpdateStrings = []string{ 140 "SwiftClient.ChunkedConnectionPoolSize=256", 141 "SwiftClient.NonChunkedConnectionPoolSize=64", 142 } 143 } 144 145 err = testConfMap.UpdateFromStrings(testConfUpdateStrings) 146 if nil != err { 147 t.Fatalf("testConfMap.UpdateFromStrings(testConfUpdateStrings) failed: %v", err) 148 } 149 150 signalHandlerIsArmedWG.Add(1) 151 testRamswiftDoneChan = make(chan bool, 1) 152 go ramswift.Daemon("/dev/null", testConfMapStrings, &signalHandlerIsArmedWG, testRamswiftDoneChan, unix.SIGTERM) 153 154 signalHandlerIsArmedWG.Wait() 155 156 err = transitions.Up(testConfMap) 157 if nil != err { 158 t.Fatalf("transitions.Up() failed: %v", err) 159 } 160 161 testVolumeHandle, err = FetchVolumeHandleByVolumeName("TestVolume") 162 if nil != err { 163 t.Fatalf("fs.FetchVolumeHandleByVolumeName() failed: %v", err) 164 } 165 testVolumeStruct, ok = testVolumeHandle.(*volumeStruct) 166 if !ok { 167 t.Fatalf("fs.Mount() returned !ok") 168 } 169 } 170 171 func testTeardown(t *testing.T) { 172 var ( 173 err error 174 testDir string 175 ) 176 177 err = transitions.Down(testConfMap) 178 if nil != err { 179 t.Fatalf("transitions.Down() failed: %v", err) 180 } 181 182 _ = syscall.Kill(syscall.Getpid(), unix.SIGTERM) 183 _ = <-testRamswiftDoneChan 184 185 // Run GC to reclaim memory before we proceed to next test 186 runtime.GC() 187 188 testDir, err = os.Getwd() 189 if nil != err { 190 t.Fatalf("os.Getwd() failed: %v", err) 191 } 192 193 err = os.Chdir("..") 194 if nil != err { 195 t.Fatalf("os.Chdir() failed: %v", err) 196 } 197 198 err = os.RemoveAll(testDir) 199 if nil != err { 200 t.Fatalf("os.RemoveAll() failed: %v", err) 201 } 202 }