featurebase/querycontext/dot_test.go
Seebs 7b434cd11c initial implementation of RBF backend
This provides us with most of the existing Tx interface, split
across QueryRead and QueryWrite. The functions not included here
are the ones that are used *only* for anti-entropy (ForEach
and ForEachRange).

We add additional testing to verify that TxStores are getting
closed correctly, to go with cleaning up the test directories they're
made in.

We also introduce some test wrappers that can automatically
fail tests on error, so tests don't need to be full of error
checks.

Also, now that I'm starting to think more about the flow of
writing tests using QueryScope, we add the missing "full
database" scope option, and make the Add methods return
their operand so (1) you can chain them, (2) you can use
the AddIndex(...) inline in a NewWriteQueryContext.

Also addressed a plausible performance concern in shardList,
and some comments that were stale or incorrect.

The test coverage here is skimpy on the actual RBF-calling
functions because those are trivial. We do, however, significantly
expand coverage in the random write requests, which are now
a mix of random writes and random reads, and add test cases
that at least hit a lot of the error checks once.

The Error() method is changed to be like (testing.T).Error(),
taking ...interface{} and using fmt.Sprint on them.

There's also some minor tweaks such as making the visualizations
more consistent, testing visualization generation on two kinds
of keysplitter, and so on.
2022-11-04 14:08:23 -05:00

42 lines
1.3 KiB
Go

// Copyright 2022 Molecula Corp (DBA FeatureBase). All rights reserved.
package querycontext
import (
"context"
"os"
"testing"
)
func TestDot(t *testing.T) {
// test this with two splitters, one of which is the default indexShardKeySplitter. the second one will overwrite
// the output from the first one.
for _, splitter := range []KeySplitter{&flexibleKeySplitter{splitIndexes: map[IndexName]struct{}{"i": {}}}, nil} {
txs := testTxStore(t, "foo", splitter)
file, err := os.Create("test.dot")
if err != nil {
t.Fatalf("creating file: %v", err)
}
defer file.Close()
q, _ := txs.NewWriteQueryContext(context.Background(), txs.Scope().AddIndex("i").AddIndexShards("k", 0))
defer q.Release()
q.NewWrite("i", "f", "v", 0)
q.NewWrite("i", "g", "v", 0)
q.NewWrite("i", "f", "v", 1)
// read, but it's in a writable thing, so still creates rbfQueryWrite
q.NewRead("i", "f", "v", 2)
q.NewRead("j", "f", "v", 0)
q2, _ := txs.NewQueryContext(context.Background())
defer q2.Release()
q2.NewRead("i", "f", "v", 0)
q2.NewRead("i", "g", "v", 0)
var dg dotGraph
// we know what we actually have here...
inner := txs.inner
dg.enqueue(inner.(*rbfTxStore))
dg.build(5)
err = dg.Write(file)
if err != nil {
t.Fatalf("writing dot: %v", err)
}
}
}