github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/httpserver/setup_teardown_test.go (about) 1 package httpserver 2 3 import ( 4 "sync" 5 "syscall" 6 "testing" 7 8 "golang.org/x/sys/unix" 9 10 "github.com/swiftstack/ProxyFS/conf" 11 "github.com/swiftstack/ProxyFS/ramswift" 12 "github.com/swiftstack/ProxyFS/transitions" 13 ) 14 15 var ( 16 ramswiftDoneChan chan bool // our global ramswiftDoneChan used during testTeardown() to know ramswift is, indeed, down 17 testConfMap conf.ConfMap 18 ) 19 20 func testSetup(t *testing.T) { 21 var ( 22 err error 23 signalHandlerIsArmedWG sync.WaitGroup 24 testConfMapStrings []string 25 testConfUpdateStrings []string 26 ) 27 28 testConfMapStrings = []string{ 29 "Stats.IPAddr=localhost", 30 "Stats.UDPPort=52184", 31 "Stats.BufferLength=100", 32 "Stats.MaxLatency=1s", 33 "Logging.LogFilePath=/dev/null", 34 "Logging.LogToConsole=false", 35 "SwiftClient.NoAuthIPAddr=127.0.0.1", 36 "SwiftClient.NoAuthTCPPort=35262", 37 "SwiftClient.Timeout=10s", 38 "SwiftClient.RetryLimit=3", 39 "SwiftClient.RetryLimitObject=3", 40 "SwiftClient.RetryDelay=10ms", 41 "SwiftClient.RetryDelayObject=10ms", 42 "SwiftClient.RetryExpBackoff=1.2", 43 "SwiftClient.RetryExpBackoffObject=2.0", 44 "SwiftClient.ChunkedConnectionPoolSize=256", 45 "SwiftClient.NonChunkedConnectionPoolSize=64", 46 "Peer:Peer0.PublicIPAddr=127.0.0.1", 47 "Peer:Peer0.PrivateIPAddr=127.0.0.1", 48 "Peer:Peer0.ReadCacheQuotaFraction=0.20", 49 "Cluster.Peers=Peer0", 50 "Cluster.WhoAmI=Peer0", 51 "Cluster.PrivateClusterUDPPort=18123", 52 "Cluster.UDPPacketSendSize=1400", 53 "Cluster.UDPPacketRecvSize=1500", 54 "Cluster.UDPPacketCapPerMessage=5", 55 "Cluster.HeartBeatDuration=1s", 56 "Cluster.HeartBeatMissLimit=3", 57 "Cluster.MessageQueueDepthPerPeer=4", 58 "Cluster.MaxRequestDuration=1s", 59 "Cluster.LivenessCheckerEnable=true", 60 "Cluster.LivenessCheckRedundancy=2", 61 "FSGlobals.VolumeGroupList=", 62 "FSGlobals.CheckpointHeaderConsensusAttempts=5", 63 "FSGlobals.MountRetryLimit=6", 64 "FSGlobals.MountRetryDelay=1s", 65 "FSGlobals.MountRetryExpBackoff=2", 66 "FSGlobals.LogCheckpointHeaderPosts=true", 67 "FSGlobals.TryLockBackoffMin=10ms", 68 "FSGlobals.TryLockBackoffMax=50ms", 69 "FSGlobals.TryLockSerializationThreshhold=5", 70 "FSGlobals.SymlinkMax=32", 71 "FSGlobals.CoalesceElementChunkSize=16", 72 "FSGlobals.InodeRecCacheEvictLowLimit=10000", 73 "FSGlobals.InodeRecCacheEvictHighLimit=10010", 74 "FSGlobals.LogSegmentRecCacheEvictLowLimit=10000", 75 "FSGlobals.LogSegmentRecCacheEvictHighLimit=10010", 76 "FSGlobals.BPlusTreeObjectCacheEvictLowLimit=10000", 77 "FSGlobals.BPlusTreeObjectCacheEvictHighLimit=10010", 78 "FSGlobals.DirEntryCacheEvictLowLimit=10000", 79 "FSGlobals.DirEntryCacheEvictHighLimit=10010", 80 "FSGlobals.FileExtentMapEvictLowLimit=10000", 81 "FSGlobals.FileExtentMapEvictHighLimit=10010", 82 "FSGlobals.EtcdEnabled=false", 83 "JSONRPCServer.TCPPort=12346", // 12346 instead of 12345 so that test can run if proxyfsd is already running 84 "JSONRPCServer.FastTCPPort=32346", // ...and similarly here... 85 "JSONRPCServer.DataPathLogging=false", 86 "JSONRPCServer.MinLeaseDuration=250ms", 87 "JSONRPCServer.LeaseInterruptInterval=250ms", 88 "JSONRPCServer.LeaseInterruptLimit=20", 89 "RamSwiftInfo.MaxAccountNameLength=256", 90 "RamSwiftInfo.MaxContainerNameLength=256", 91 "RamSwiftInfo.MaxObjectNameLength=1024", 92 "RamSwiftInfo.AccountListingLimit=10000", 93 "RamSwiftInfo.ContainerListingLimit=10000", 94 95 "HTTPServer.TCPPort=53461", 96 } 97 98 testConfMap, err = conf.MakeConfMapFromStrings(testConfMapStrings) 99 if nil != err { 100 t.Fatalf("conf.MakeConfMapFromStrings() failed: %v", err) 101 } 102 103 err = testConfMap.UpdateFromStrings(testConfUpdateStrings) 104 if nil != err { 105 t.Fatalf("testConfMap.UpdateFromStrings(testConfUpdateStrings) failed: %v", err) 106 } 107 108 signalHandlerIsArmedWG.Add(1) 109 ramswiftDoneChan = make(chan bool, 1) 110 go ramswift.Daemon("/dev/null", testConfMapStrings, &signalHandlerIsArmedWG, ramswiftDoneChan, unix.SIGTERM) 111 112 signalHandlerIsArmedWG.Wait() 113 114 err = transitions.Up(testConfMap) 115 if nil != err { 116 t.Fatalf("transitions.Up() failed: %v", err) 117 } 118 } 119 120 func testTeardown(t *testing.T) { 121 var ( 122 err error 123 ) 124 125 err = transitions.Down(testConfMap) 126 if nil != err { 127 t.Fatalf("transitions.Down() failed: %v", err) 128 } 129 130 _ = syscall.Kill(syscall.Getpid(), unix.SIGTERM) 131 _ = <-ramswiftDoneChan 132 }