diff --git a/command/marshal_test.go b/command/marshal_test.go index 0133306a..a0089632 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,40 @@ 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 < 100; 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