From f8e93871c036802c090d72640b4d4d5a3fd30792 Mon Sep 17 00:00:00 2001 From: reesporte Date: Wed, 17 Nov 2021 08:51:28 -0600 Subject: [PATCH] refactor safeCopy to pure function and add unit test --- executor.go | 4 ++-- executor_internal_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index 686379609..3668f9279 100644 --- a/executor.go +++ b/executor.go @@ -254,7 +254,7 @@ func (e *executor) Execute(ctx context.Context, index string, q *pql.Query, shar } } // Must copy out of Tx data before Commiting, because it will become invalid afterwards. - respSafeNoTxData := e.safeCopy(resp) + respSafeNoTxData := safeCopy(resp) // Commit transactions if writing; else let the defer grp.Abort do the rollbacks. if needWriteTxn { @@ -267,7 +267,7 @@ func (e *executor) Execute(ctx context.Context, index string, q *pql.Query, shar // safeCopy copies everything in resp that has Bitmap material, // to avoid anything coming from the mmap-ed Tx storage. -func (e *executor) safeCopy(resp QueryResponse) (out QueryResponse) { +func safeCopy(resp QueryResponse) (out QueryResponse) { out = QueryResponse{ Err: resp.Err, // error Profile: resp.Profile, // *tracing.Profile diff --git a/executor_internal_test.go b/executor_internal_test.go index b752957ef..ce860c46c 100644 --- a/executor_internal_test.go +++ b/executor_internal_test.go @@ -475,3 +475,15 @@ func TestGetSorter(t *testing.T) { }) } } + +func TestExecutorSafeCopyDistinctTimestamp(t *testing.T) { + result := DistinctTimestamp{Values: []string{"test", "test"}, Name: "test"} + results := make([]interface{}, 1) + results[0] = result + + response := QueryResponse{Results: results, Err: nil, Profile: nil} + copied := safeCopy(response) + if !reflect.DeepEqual(copied.Results, response.Results) { + t.Fatalf("Did not copy results. got %+v, want %+v", copied.Results, response.Results) + } +}