diff --git a/nsqd/channel_test.go b/nsqd/channel_test.go index 93a4cd846..53c17ab38 100644 --- a/nsqd/channel_test.go +++ b/nsqd/channel_test.go @@ -1,6 +1,7 @@ package nsqd import ( + "os" "strconv" "testing" "time" @@ -11,6 +12,7 @@ func TestPutMessage(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_put_message" + strconv.Itoa(int(time.Now().Unix())) @@ -31,6 +33,7 @@ func TestPutMessage2Chan(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_put_message_2chan" + strconv.Itoa(int(time.Now().Unix())) @@ -58,6 +61,7 @@ func TestInFlightWorker(t *testing.T) { opts.Logger = newTestLogger(t) opts.MsgTimeout = 100 * time.Millisecond _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_in_flight_worker" + strconv.Itoa(int(time.Now().Unix())) @@ -98,6 +102,7 @@ func TestChannelEmpty(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_channel_empty" + strconv.Itoa(int(time.Now().Unix())) @@ -130,6 +135,7 @@ func TestChannelEmptyConsumer(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, _ := mustConnectNSQD(tcpAddr) diff --git a/nsqd/diskqueue_test.go b/nsqd/diskqueue_test.go index b93805fc6..bafec2118 100644 --- a/nsqd/diskqueue_test.go +++ b/nsqd/diskqueue_test.go @@ -2,6 +2,8 @@ package nsqd import ( "bufio" + "fmt" + "io/ioutil" "os" "path" "strconv" @@ -15,12 +17,17 @@ func TestDiskQueue(t *testing.T) { l := newTestLogger(t) dqName := "test_disk_queue" + strconv.Itoa(int(time.Now().Unix())) - dq := newDiskQueue(dqName, os.TempDir(), 1024, 2500, 2*time.Second, l) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + dq := newDiskQueue(dqName, tmpDir, 1024, 2500, 2*time.Second, l) nequal(t, dq, nil) equal(t, dq.Depth(), int64(0)) msg := []byte("test") - err := dq.Put(msg) + err = dq.Put(msg) equal(t, err, nil) equal(t, dq.Depth(), int64(1)) @@ -31,7 +38,12 @@ func TestDiskQueue(t *testing.T) { func TestDiskQueueRoll(t *testing.T) { l := newTestLogger(t) dqName := "test_disk_queue_roll" + strconv.Itoa(int(time.Now().Unix())) - dq := newDiskQueue(dqName, os.TempDir(), 100, 2500, 2*time.Second, l) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + dq := newDiskQueue(dqName, tmpDir, 100, 2500, 2*time.Second, l) nequal(t, dq, nil) equal(t, dq.Depth(), int64(0)) @@ -55,7 +67,12 @@ func assertFileNotExist(t *testing.T, fn string) { func TestDiskQueueEmpty(t *testing.T) { l := newTestLogger(t) dqName := "test_disk_queue_empty" + strconv.Itoa(int(time.Now().Unix())) - dq := newDiskQueue(dqName, os.TempDir(), 100, 2500, 2*time.Second, l) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + dq := newDiskQueue(dqName, tmpDir, 100, 2500, 2*time.Second, l) nequal(t, dq, nil) equal(t, dq.Depth(), int64(0)) @@ -118,7 +135,12 @@ func TestDiskQueueEmpty(t *testing.T) { func TestDiskQueueCorruption(t *testing.T) { l := newTestLogger(t) dqName := "test_disk_queue_corruption" + strconv.Itoa(int(time.Now().Unix())) - dq := newDiskQueue(dqName, os.TempDir(), 1000, 5, 2*time.Second, l) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + dq := newDiskQueue(dqName, tmpDir, 1000, 5, 2*time.Second, l) msg := make([]byte, 123) for i := 0; i < 25; i++ { @@ -149,7 +171,12 @@ func TestDiskQueueTorture(t *testing.T) { l := newTestLogger(t) dqName := "test_disk_queue_torture" + strconv.Itoa(int(time.Now().Unix())) - dq := newDiskQueue(dqName, os.TempDir(), 262144, 2500, 2*time.Second, l) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + dq := newDiskQueue(dqName, tmpDir, 262144, 2500, 2*time.Second, l) nequal(t, dq, nil) equal(t, dq.Depth(), int64(0)) @@ -190,7 +217,7 @@ func TestDiskQueueTorture(t *testing.T) { t.Logf("restarting diskqueue") - dq = newDiskQueue(dqName, os.TempDir(), 262144, 2500, 2*time.Second, l) + dq = newDiskQueue(dqName, tmpDir, 262144, 2500, 2*time.Second, l) nequal(t, dq, nil) equal(t, dq.Depth(), depth) @@ -233,7 +260,12 @@ func BenchmarkDiskQueuePut(b *testing.B) { b.StopTimer() l := newTestLogger(b) dqName := "bench_disk_queue_put" + strconv.Itoa(b.N) + strconv.Itoa(int(time.Now().Unix())) - dq := newDiskQueue(dqName, os.TempDir(), 1024768*100, 2500, 2*time.Second, l) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + dq := newDiskQueue(dqName, tmpDir, 1024768*100, 2500, 2*time.Second, l) size := 1024 b.SetBytes(int64(size)) data := make([]byte, size) @@ -247,7 +279,12 @@ func BenchmarkDiskQueuePut(b *testing.B) { func BenchmarkDiskWrite(b *testing.B) { b.StopTimer() fileName := "bench_disk_queue_put" + strconv.Itoa(b.N) + strconv.Itoa(int(time.Now().Unix())) - f, _ := os.OpenFile(path.Join(os.TempDir(), fileName), os.O_RDWR|os.O_CREATE, 0600) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + f, _ := os.OpenFile(path.Join(tmpDir, fileName), os.O_RDWR|os.O_CREATE, 0600) size := 256 b.SetBytes(int64(size)) data := make([]byte, size) @@ -262,7 +299,12 @@ func BenchmarkDiskWrite(b *testing.B) { func BenchmarkDiskWriteBuffered(b *testing.B) { b.StopTimer() fileName := "bench_disk_queue_put" + strconv.Itoa(b.N) + strconv.Itoa(int(time.Now().Unix())) - f, _ := os.OpenFile(path.Join(os.TempDir(), fileName), os.O_RDWR|os.O_CREATE, 0600) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + f, _ := os.OpenFile(path.Join(tmpDir, fileName), os.O_RDWR|os.O_CREATE, 0600) size := 256 b.SetBytes(int64(size)) data := make([]byte, size) @@ -286,7 +328,12 @@ func BenchmarkDiskQueueGet(b *testing.B) { b.StopTimer() l := newTestLogger(b) dqName := "bench_disk_queue_get" + strconv.Itoa(b.N) + strconv.Itoa(int(time.Now().Unix())) - dq := newDiskQueue(dqName, os.TempDir(), 1024768, 2500, 2*time.Second, l) + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + defer os.RemoveAll(tmpDir) + dq := newDiskQueue(dqName, tmpDir, 1024768, 2500, 2*time.Second, l) for i := 0; i < b.N; i++ { dq.Put([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaa")) } diff --git a/nsqd/http_test.go b/nsqd/http_test.go index b09b59be9..3744ba44c 100644 --- a/nsqd/http_test.go +++ b/nsqd/http_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net" "net/http" + "os" "runtime" "strconv" "sync" @@ -21,6 +22,7 @@ func TestHTTPput(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_put" + strconv.Itoa(int(time.Now().Unix())) @@ -43,6 +45,7 @@ func TestHTTPputEmpty(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_put_empty" + strconv.Itoa(int(time.Now().Unix())) @@ -66,6 +69,7 @@ func TestHTTPmput(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_mput" + strconv.Itoa(int(time.Now().Unix())) @@ -94,6 +98,7 @@ func TestHTTPmputEmpty(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_mput_empty" + strconv.Itoa(int(time.Now().Unix())) @@ -124,6 +129,7 @@ func TestHTTPmputBinary(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_mput_bin" + strconv.Itoa(int(time.Now().Unix())) @@ -156,6 +162,7 @@ func TestHTTPSRequire(t *testing.T) { opts.TLSKey = "./test/certs/server.key" opts.TLSClientAuthPolicy = "require" _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_put_req" + strconv.Itoa(int(time.Now().Unix())) @@ -201,10 +208,10 @@ func TestHTTPSRequireVerify(t *testing.T) { opts.TLSRootCAFile = "./test/certs/ca.pem" opts.TLSClientAuthPolicy = "require-verify" _, httpAddr, nsqd := mustStartNSQD(opts) - httpsAddr := nsqd.httpsListener.Addr().(*net.TCPAddr) - + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() + httpsAddr := nsqd.httpsListener.Addr().(*net.TCPAddr) topicName := "test_http_put_req_verf" + strconv.Itoa(int(time.Now().Unix())) topic := nsqd.GetTopic(topicName) @@ -266,7 +273,7 @@ func TestTLSRequireVerifyExceptHTTP(t *testing.T) { opts.TLSClientAuthPolicy = "require-verify" opts.TLSRequired = TLSRequiredExceptHTTP _, httpAddr, nsqd := mustStartNSQD(opts) - + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_req_verf_except_http" + strconv.Itoa(int(time.Now().Unix())) @@ -290,6 +297,7 @@ func TestHTTPDeprecatedTopicChannel(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_topic_channel" + strconv.Itoa(int(time.Now().Unix())) @@ -386,6 +394,7 @@ func TestHTTPTransitionTopicChannel(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() client := http.Client{} @@ -507,6 +516,7 @@ func TestHTTPV1TopicChannel(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_http_topic_channel2" + strconv.Itoa(int(time.Now().Unix())) @@ -614,6 +624,7 @@ func BenchmarkHTTPput(b *testing.B) { opts.Logger = newTestLogger(b) opts.MemQueueSize = int64(b.N) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) msg := make([]byte, 256) topicName := "bench_http_put" + strconv.Itoa(int(time.Now().Unix())) url := fmt.Sprintf("http://%s/put?topic=%s", httpAddr, topicName) @@ -653,9 +664,11 @@ func TestHTTPgetStatusJSON(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) + defer nsqd.Exit() + nsqd.startTime = testTime expectedJSON := fmt.Sprintf(`{"status_code":200,"status_txt":"OK","data":{"version":"%v","health":"OK","start_time":%v,"topics":[]}}`, version.Binary, testTime.Unix()) - defer nsqd.Exit() url := fmt.Sprintf("http://%s/stats?format=json", httpAddr) resp, err := http.Get(url) @@ -671,9 +684,11 @@ func TestHTTPgetStatusText(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, httpAddr, nsqd := mustStartNSQD(opts) - nsqd.startTime = testTime + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() + nsqd.startTime = testTime + url := fmt.Sprintf("http://%s/stats?format=text", httpAddr) resp, err := http.Get(url) equal(t, err, nil) diff --git a/nsqd/nsqd_test.go b/nsqd/nsqd_test.go index aeb9124e5..f854deddf 100644 --- a/nsqd/nsqd_test.go +++ b/nsqd/nsqd_test.go @@ -3,6 +3,7 @@ package nsqd import ( "fmt" "io/ioutil" + "os" "path" "path/filepath" "reflect" @@ -81,6 +82,9 @@ func TestStartup(t *testing.T) { opts.MemQueueSize = 100 opts.MaxBytesPerFile = 10240 _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) + + origDataPath := opts.DataPath topicName := "nsqd_test" + strconv.Itoa(int(time.Now().Unix())) @@ -147,6 +151,7 @@ func TestStartup(t *testing.T) { opts.Logger = newTestLogger(t) opts.MemQueueSize = 100 opts.MaxBytesPerFile = 10240 + opts.DataPath = origDataPath _, _, nsqd = mustStartNSQD(opts) go func() { @@ -190,6 +195,7 @@ func TestEphemeralTopicsAndChannels(t *testing.T) { opts.Logger = newTestLogger(t) opts.MemQueueSize = 100 _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) topicName := "ephemeral_topic" + strconv.Itoa(int(time.Now().Unix())) + "#ephemeral" doneExitChan := make(chan int) @@ -240,6 +246,7 @@ func TestPauseMetadata(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() // avoid concurrency issue of async PersistMetadata() calls diff --git a/nsqd/protocol_v2_test.go b/nsqd/protocol_v2_test.go index 80139fead..15b917410 100644 --- a/nsqd/protocol_v2_test.go +++ b/nsqd/protocol_v2_test.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "io" + "io/ioutil" "math" "math/rand" "net" @@ -30,7 +31,13 @@ func mustStartNSQD(opts *nsqdOptions) (*net.TCPAddr, *net.TCPAddr, *NSQD) { opts.TCPAddress = "127.0.0.1:0" opts.HTTPAddress = "127.0.0.1:0" opts.HTTPSAddress = "127.0.0.1:0" - opts.DataPath = os.TempDir() + if opts.DataPath == "" { + tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano())) + if err != nil { + panic(err) + } + opts.DataPath = tmpDir + } nsqd := NewNSQD(opts) nsqd.Main() return nsqd.tcpListener.Addr().(*net.TCPAddr), @@ -119,6 +126,7 @@ func TestBasicV2(t *testing.T) { opts.Logger = newTestLogger(t) opts.ClientTimeout = 60 * time.Second tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_v2" + strconv.Itoa(int(time.Now().Unix())) @@ -153,6 +161,7 @@ func TestMultipleConsumerV2(t *testing.T) { opts.Logger = newTestLogger(t) opts.ClientTimeout = 60 * time.Second tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_multiple_v2" + strconv.Itoa(int(time.Now().Unix())) @@ -199,6 +208,7 @@ func TestClientTimeout(t *testing.T) { opts.ClientTimeout = 150 * time.Millisecond opts.Verbose = true tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -234,6 +244,7 @@ func TestClientHeartbeat(t *testing.T) { opts.Logger = newTestLogger(t) opts.ClientTimeout = 200 * time.Millisecond tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -270,6 +281,7 @@ func TestClientHeartbeatDisableSUB(t *testing.T) { opts.ClientTimeout = 200 * time.Millisecond opts.Verbose = true tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -287,6 +299,7 @@ func TestClientHeartbeatDisable(t *testing.T) { opts.Logger = newTestLogger(t) opts.ClientTimeout = 100 * time.Millisecond tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -308,6 +321,7 @@ func TestMaxHeartbeatIntervalValid(t *testing.T) { opts.Logger = newTestLogger(t) opts.MaxHeartbeatInterval = 300 * time.Second tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -325,6 +339,7 @@ func TestMaxHeartbeatIntervalInvalid(t *testing.T) { opts.Logger = newTestLogger(t) opts.MaxHeartbeatInterval = 300 * time.Second tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -344,6 +359,7 @@ func TestPausing(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -407,6 +423,7 @@ func TestEmptyCommand(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -426,6 +443,7 @@ func TestSizeLimits(t *testing.T) { opts.MaxMsgSize = 100 opts.MaxBodySize = 1000 tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -541,6 +559,7 @@ func TestTouch(t *testing.T) { opts.Verbose = true opts.MsgTimeout = 150 * time.Millisecond tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_touch" + strconv.Itoa(int(time.Now().Unix())) @@ -586,6 +605,7 @@ func TestMaxRdyCount(t *testing.T) { opts.Verbose = true opts.MaxRdyCount = 50 tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_max_rdy_count" + strconv.Itoa(int(time.Now().Unix())) @@ -631,6 +651,7 @@ func TestFatalError(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -657,6 +678,7 @@ func TestOutputBuffering(t *testing.T) { opts.MaxOutputBufferSize = 512 * 1024 opts.MaxOutputBufferTimeout = time.Second tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_output_buffering" + strconv.Itoa(int(time.Now().Unix())) @@ -708,6 +730,7 @@ func TestOutputBufferingValidity(t *testing.T) { opts.MaxOutputBufferSize = 512 * 1024 opts.MaxOutputBufferTimeout = time.Second tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -750,6 +773,7 @@ func TestTLS(t *testing.T) { opts.TLSCert = "./test/certs/server.pem" opts.TLSKey = "./test/certs/server.key" tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -790,6 +814,7 @@ func TestTLSRequired(t *testing.T) { opts.TLSRequired = TLSRequiredExceptHTTP tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_tls_required" + strconv.Itoa(int(time.Now().Unix())) @@ -838,6 +863,7 @@ func TestTLSAuthRequire(t *testing.T) { opts.TLSClientAuthPolicy = "require" tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() // No Certs @@ -904,6 +930,7 @@ func TestTLSAuthRequireVerify(t *testing.T) { opts.TLSClientAuthPolicy = "require-verify" tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() // with no cert @@ -988,6 +1015,7 @@ func TestDeflate(t *testing.T) { opts.Verbose = true opts.DeflateEnabled = true tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -1023,6 +1051,7 @@ func TestSnappy(t *testing.T) { opts.Verbose = true opts.SnappyEnabled = true tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -1077,6 +1106,7 @@ func TestTLSDeflate(t *testing.T) { opts.TLSCert = "./test/certs/cert.pem" opts.TLSKey = "./test/certs/key.pem" tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -1131,6 +1161,7 @@ func TestSampling(t *testing.T) { opts.Verbose = true opts.MaxRdyCount = int64(num) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -1199,6 +1230,7 @@ func TestTLSSnappy(t *testing.T) { opts.TLSCert = "./test/certs/cert.pem" opts.TLSKey = "./test/certs/key.pem" tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -1246,6 +1278,7 @@ func TestClientMsgTimeout(t *testing.T) { opts.Logger = newTestLogger(t) opts.Verbose = true tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_cmsg_timeout" + strconv.Itoa(int(time.Now().Unix())) @@ -1296,6 +1329,7 @@ func TestBadFin(t *testing.T) { opts.Logger = newTestLogger(t) opts.Verbose = true tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -1355,6 +1389,7 @@ func runAuthTest(t *testing.T, authResponse, authSecret, authError, authSuccess opts.Verbose = true opts.AuthHTTPAddresses = []string{addr.Host} tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) @@ -1399,6 +1434,7 @@ func benchmarkProtocolV2Pub(b *testing.B, size int) { opts.Logger = newTestLogger(b) opts.MemQueueSize = int64(b.N) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) msg := make([]byte, size) batchSize := int(opts.MaxBodySize) / size batch := make([][]byte, batchSize) @@ -1469,6 +1505,7 @@ func benchmarkProtocolV2Sub(b *testing.B, size int) { opts.Logger = newTestLogger(b) opts.MemQueueSize = int64(b.N) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) msg := make([]byte, size) topicName := "bench_v2_sub" + strconv.Itoa(b.N) + strconv.Itoa(int(time.Now().Unix())) topic := nsqd.GetTopic(topicName) @@ -1565,6 +1602,7 @@ func benchmarkProtocolV2MultiSub(b *testing.B, num int) { opts.Logger = newTestLogger(b) opts.MemQueueSize = int64(b.N) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) msg := make([]byte, 256) b.SetBytes(int64(len(msg) * num)) diff --git a/nsqd/stats_test.go b/nsqd/stats_test.go index 93c97f96c..c8834d729 100644 --- a/nsqd/stats_test.go +++ b/nsqd/stats_test.go @@ -3,6 +3,7 @@ package nsqd import ( "encoding/json" "fmt" + "os" "strconv" "testing" "time" @@ -15,6 +16,7 @@ func TestStats(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) tcpAddr, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_stats" + strconv.Itoa(int(time.Now().Unix())) @@ -45,6 +47,7 @@ func TestClientAttributes(t *testing.T) { opts.Verbose = true opts.SnappyEnabled = true tcpAddr, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() conn, err := mustConnectNSQD(tcpAddr) diff --git a/nsqd/topic_test.go b/nsqd/topic_test.go index 07e03eeea..3d637b0a5 100644 --- a/nsqd/topic_test.go +++ b/nsqd/topic_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "net/http" + "os" "runtime" "strconv" "testing" @@ -15,6 +16,7 @@ func TestGetTopic(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topic1 := nsqd.GetTopic("test") @@ -33,6 +35,7 @@ func TestGetChannel(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topic := nsqd.GetTopic("test") @@ -61,6 +64,7 @@ func TestHealth(t *testing.T) { opts.Logger = newTestLogger(t) opts.MemQueueSize = 2 _, httpAddr, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topic := nsqd.GetTopic("test") @@ -95,6 +99,7 @@ func TestDeletes(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topic := nsqd.GetTopic("test") @@ -119,6 +124,7 @@ func TestDeleteLast(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topic := nsqd.GetTopic("test") @@ -141,6 +147,7 @@ func TestPause(t *testing.T) { opts := NewNSQDOptions() opts.Logger = newTestLogger(t) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() topicName := "test_topic_pause" + strconv.Itoa(int(time.Now().Unix())) @@ -176,6 +183,7 @@ func BenchmarkTopicPut(b *testing.B) { opts.Logger = newTestLogger(b) opts.MemQueueSize = int64(b.N) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() b.StartTimer() @@ -194,6 +202,7 @@ func BenchmarkTopicToChannelPut(b *testing.B) { opts.Logger = newTestLogger(b) opts.MemQueueSize = int64(b.N) _, _, nsqd := mustStartNSQD(opts) + defer os.RemoveAll(opts.DataPath) defer nsqd.Exit() channel := nsqd.GetTopic(topicName).GetChannel(channelName) b.StartTimer()