mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 11:27:50 +00:00
refactor safeCopy to pure function and add unit test
This commit is contained in:
parent
7390ae072d
commit
f8e93871c0
2 changed files with 14 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue