From 8ab01c99c0eb946611f99eaa976a41aa5cedb35b Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Thu, 15 Nov 2018 17:00:03 -0800 Subject: [PATCH] test(tsdb/tsm1): skip long tests in short mode The tsdb/tsm1 package was one of the test suites that took the longest to run in platform with go test -short. The rule of thumb on the Go project is that short mode should skip any individual test that takes longer than one second. This change skips two such tests, and it eliminates a string concatenation loop in two other tests, so that they report completion in "0.00s" rather than about 0.94s, on my machine. These cumulative changes take `go test -short ./tsdb/tsm1` from about 14 seconds to about 7 seconds on my machine. --- tsdb/tsm1/engine_test.go | 4 ++++ tsdb/tsm1/file_store_test.go | 5 ++++- tsdb/tsm1/writer_test.go | 15 ++++----------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tsdb/tsm1/engine_test.go b/tsdb/tsm1/engine_test.go index 2c35d94c17..5d2da0c45f 100644 --- a/tsdb/tsm1/engine_test.go +++ b/tsdb/tsm1/engine_test.go @@ -656,6 +656,10 @@ func TestEngine_DeleteSeriesRange_OutsideTime(t *testing.T) { } func TestEngine_LastModified(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + // Create a few points. p1 := MustParsePointString("cpu,host=A value=1.1 1000000000") p2 := MustParsePointString("cpu,host=B value=1.2 2000000000") diff --git a/tsdb/tsm1/file_store_test.go b/tsdb/tsm1/file_store_test.go index ef62b6e9c6..a17ef51cf5 100644 --- a/tsdb/tsm1/file_store_test.go +++ b/tsdb/tsm1/file_store_test.go @@ -2418,6 +2418,10 @@ func TestFileStore_Remove(t *testing.T) { } func TestFileStore_Replace(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + dir := MustTempDir() defer os.RemoveAll(dir) @@ -2505,7 +2509,6 @@ func TestFileStore_Replace(t *testing.T) { if _, err := os.Stat(files[2]); err != nil { t.Fatalf("stat file: %v", err) } - } func TestFileStore_Open_Deleted(t *testing.T) { diff --git a/tsdb/tsm1/writer_test.go b/tsdb/tsm1/writer_test.go index c355426970..b7bf78dc0d 100644 --- a/tsdb/tsm1/writer_test.go +++ b/tsdb/tsm1/writer_test.go @@ -556,12 +556,8 @@ func TestTSMWriter_WriteBlock_MaxKey(t *testing.T) { t.Fatalf("unexpected error creating writer: %v", err) } - var key string - for i := 0; i < 100000; i++ { - key += "a" - } - - if err := w.WriteBlock([]byte(key), 0, 0, nil); err != tsm1.ErrMaxKeyLengthExceeded { + key := bytes.Repeat([]byte("a"), 100000) + if err := w.WriteBlock(key, 0, 0, nil); err != tsm1.ErrMaxKeyLengthExceeded { t.Fatalf("expected max key length error writing key: %v", err) } } @@ -577,11 +573,8 @@ func TestTSMWriter_Write_MaxKey(t *testing.T) { t.Fatalf("unexpected error created writer: %v", err) } - var key string - for i := 0; i < 100000; i++ { - key += "a" - } - if err := w.Write([]byte(key), []tsm1.Value{tsm1.NewValue(0, 1.0)}); err != tsm1.ErrMaxKeyLengthExceeded { + key := bytes.Repeat([]byte("a"), 100000) + if err := w.Write(key, []tsm1.Value{tsm1.NewValue(0, 1.0)}); err != tsm1.ErrMaxKeyLengthExceeded { t.Fatalf("expected max key length error writing key: %v", err) } }