MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestSerializableState

Function TestSerializableState

xenomint/state_test.go:713–940  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

711}
712
713func TestSerializableState(t *testing.T) {
714 Convey("Given a serialzable state", t, func() {
715 var (
716 filePath = path.Join(testingDataDir, t.Name())
717 state *State
718 storage xi.Storage
719 err error
720 )
721 storage, err = xs.NewSqlite(fmt.Sprint("file:", filePath))
722 So(err, ShouldBeNil)
723 So(storage, ShouldNotBeNil)
724 state = NewState(sql.LevelSerializable, nodeID, storage)
725 So(state, ShouldNotBeNil)
726 Reset(func() {
727 // Clean database file after each pass
728 err = state.Close(true)
729 So(err, ShouldBeNil)
730 err = os.Remove(filePath)
731 So(err, ShouldBeNil)
732 err = os.Remove(fmt.Sprint(filePath, "-shm"))
733 So(err == nil || os.IsNotExist(err), ShouldBeTrue)
734 err = os.Remove(fmt.Sprint(filePath, "-wal"))
735 So(err == nil || os.IsNotExist(err), ShouldBeTrue)
736 })
737 Convey("When a basic KV table is created", func() {
738 var (
739 req = buildRequest(types.WriteQuery, []types.Query{
740 buildQuery(`CREATE TABLE t1 (k INT, v TEXT, PRIMARY KEY(k))`),
741 })
742 resp *types.Response
743 )
744 _, resp, err = state.Query(req, true)
745 So(err, ShouldBeNil)
746 So(resp, ShouldNotBeNil)
747 Convey("The state should keep consistent with committed transaction", func(c C) {
748 var (
749 count = 1000
750 insertQueries = make([]types.Query, count+2)
751 deleteQueries = make([]types.Query, count+2)
752 iReq, dReq *types.Request
753 )
754 insertQueries[0] = buildQuery(`BEGIN`)
755 deleteQueries[0] = buildQuery(`BEGIN`)
756 for i := 0; i < count; i++ {
757 insertQueries[i+1] = buildQuery(
758 `INSERT INTO t1(k, v) VALUES (?, ?)`, i, fmt.Sprintf("v%d", i),
759 )
760 deleteQueries[i+1] = buildQuery(`DELETE FROM t1 WHERE k=?`, i)
761 }
762 insertQueries[count+1] = buildQuery(`COMMIT`)
763 deleteQueries[count+1] = buildQuery(`COMMIT`)
764 iReq = buildRequest(types.WriteQuery, insertQueries)
765 dReq = buildRequest(types.WriteQuery, deleteQueries)
766
767 var (
768 wg = &sync.WaitGroup{}
769 ctx, cancel = context.WithCancel(context.Background())
770 )

Callers

nothing calls this directly

Calls 11

NewStateFunction · 0.85
PrintfFunction · 0.85
NameMethod · 0.80
WaitMethod · 0.80
buildRequestFunction · 0.70
buildQueryFunction · 0.70
CloseMethod · 0.65
QueryMethod · 0.65
RemoveMethod · 0.45
AddMethod · 0.45
PrintfMethod · 0.45

Tested by

no test coverage detected