// Copyright 2021 Molecula Corp. All rights reserved. package pilosa import ( "fmt" "math" "reflect" "strconv" "strings" "testing" "time" "github.com/molecula/featurebase/v3/pql" qc "github.com/molecula/featurebase/v3/querycontext" "github.com/molecula/featurebase/v3/roaring" "github.com/molecula/featurebase/v3/shardwidth" "github.com/stretchr/testify/require" ) // CorruptAMutex breaks a mutex in order to test the mutex-corruption stuff. // Note the horrible crime here: This is an exported function which exists only // in test builds. This is so that external tests, which aren't inside this // package, can call this exported function, and thus get access to functionality // that would otherwise not be available to them. // // This always sets row 3 in column 0 of each shard it finds. Populate the // field with existing shards first. func CorruptAMutex(tb testing.TB, field *Field, qcx qc.QueryContext) { v := field.view(viewStandard) if v == nil { tb.Fatalf("creating view failed") } frags := v.allFragments() for _, frag := range frags { func() { qw, err := frag.qcxWrite(qcx) if err != nil { tb.Fatalf("getting tx: %v", err) } // set a bonus bit, bypassing the mutex handling frag.mu.Lock() _, err = frag.unprotectedSetBit(qw, 3, (frag.shard< len(tc.expected) { t.Fatalf("unexpected view %q", views[len(tc.expected)]) } t.Logf("views: %v", views) } }