From d02695126cfc09e9dfaeb7fac56a9e9766b72f3b Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 13 Apr 2021 15:27:44 -0400 Subject: [PATCH 1/4] Ensure concurrent compression is OK Don't let https://github.com/rqlite/rqlite/issues/781 happen again. --- command/marshal_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/command/marshal_test.go b/command/marshal_test.go index 0133306a..93d39b78 100644 --- a/command/marshal_test.go +++ b/command/marshal_test.go @@ -1,6 +1,7 @@ package command import ( + "sync" "testing" "github.com/golang/protobuf/proto" @@ -212,6 +213,41 @@ func Test_MarshalWontCompressBatch(t *testing.T) { } } +func Test_MarshalCompressedConcurrent(t *testing.T) { + rm := NewRequestMarshaler() + rm.SizeThreshold = 1 + rm.ForceCompression = true + + r := &QueryRequest{ + Request: &Request{ + Statements: []*Statement{ + { + Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`, + }, + }, + }, + Timings: true, + Freshness: 100, + } + + var wg sync.WaitGroup + for i := 0; i < 10000; i++ { + wg.Add(1) + go func() { + defer wg.Done() + _, comp, err := rm.Marshal(r) + if err != nil { + t.Fatalf("failed to marshal QueryRequest: %s", err) + } + if !comp { + t.Fatal("Marshaled QueryRequest wasn't compressed") + } + }() + } + + wg.Wait() +} + func Test_MarshalWontCompressSize(t *testing.T) { rm := NewRequestMarshaler() rm.SizeThreshold = 1 From ebe86e9f0f5f98f894e0b8be06a1fcf7732ac9f4 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 13 Apr 2021 15:29:33 -0400 Subject: [PATCH 2/4] Remove superfluous blank line --- command/marshal_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/command/marshal_test.go b/command/marshal_test.go index 93d39b78..a9ef4a8a 100644 --- a/command/marshal_test.go +++ b/command/marshal_test.go @@ -244,7 +244,6 @@ func Test_MarshalCompressedConcurrent(t *testing.T) { } }() } - wg.Wait() } From 97e97bb80218d600d9cc1c9e361d9c689aa52e74 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 13 Apr 2021 16:27:39 -0400 Subject: [PATCH 3/4] Reduce number of concurrent tests --- command/marshal_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/marshal_test.go b/command/marshal_test.go index a9ef4a8a..06ee7efd 100644 --- a/command/marshal_test.go +++ b/command/marshal_test.go @@ -231,7 +231,7 @@ func Test_MarshalCompressedConcurrent(t *testing.T) { } var wg sync.WaitGroup - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { wg.Add(1) go func() { defer wg.Done() From 3b86b9c5980dbdb51d4c85381e3c81c0c0030ccd Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 14 Apr 2021 15:29:01 -0400 Subject: [PATCH 4/4] 100 test loops is sufficient Otherwise testing takes too long on CI. --- command/marshal_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/marshal_test.go b/command/marshal_test.go index 06ee7efd..a0089632 100644 --- a/command/marshal_test.go +++ b/command/marshal_test.go @@ -231,7 +231,7 @@ func Test_MarshalCompressedConcurrent(t *testing.T) { } var wg sync.WaitGroup - for i := 0; i < 1000; i++ { + for i := 0; i < 100; i++ { wg.Add(1) go func() { defer wg.Done()