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

Function TestState

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

Source from the content-addressed store, hash-verified

41)
42
43func TestState(t *testing.T) {
44 Convey("Given a chain state object", t, func() {
45 var (
46 id1 = proto.DatabaseID("db-x1")
47 fl1 = path.Join(testingDataDir, fmt.Sprint(t.Name(), "x1"))
48 fl2 = path.Join(testingDataDir, fmt.Sprint(t.Name(), "x2"))
49 st1, st2 *State
50 strg1, strg2 xi.Storage
51 err error
52 )
53 strg1, err = xs.NewSqlite(fmt.Sprint("file:", fl1))
54 So(err, ShouldBeNil)
55 So(strg1, ShouldNotBeNil)
56 st1 = NewState(sql.LevelReadUncommitted, nodeID, strg1)
57 So(st1, ShouldNotBeNil)
58 Reset(func() {
59 // Clean database file after each pass
60 err = st1.Close(true)
61 So(err, ShouldBeNil)
62 err = os.Remove(fl1)
63 So(err, ShouldBeNil)
64 err = os.Remove(fmt.Sprint(fl1, "-shm"))
65 So(err == nil || os.IsNotExist(err), ShouldBeTrue)
66 err = os.Remove(fmt.Sprint(fl1, "-wal"))
67 So(err == nil || os.IsNotExist(err), ShouldBeTrue)
68 })
69 strg2, err = xs.NewSqlite(fmt.Sprint("file:", fl2))
70 So(err, ShouldBeNil)
71 So(strg1, ShouldNotBeNil)
72 st2 = NewState(sql.LevelReadUncommitted, nodeID, strg2)
73 So(st1, ShouldNotBeNil)
74 Reset(func() {
75 // Clean database file after each pass
76 err = st2.Close(true)
77 So(err, ShouldBeNil)
78 err = os.Remove(fl2)
79 So(err, ShouldBeNil)
80 err = os.Remove(fmt.Sprint(fl2, "-shm"))
81 So(err == nil || os.IsNotExist(err), ShouldBeTrue)
82 err = os.Remove(fmt.Sprint(fl2, "-wal"))
83 So(err == nil || os.IsNotExist(err), ShouldBeTrue)
84 })
85 Convey("When storage is closed", func() {
86 err = st1.Close(false)
87 So(err, ShouldBeNil)
88 Convey("The storage should report error for any incoming query", func() {
89 var req = buildRequest(types.WriteQuery, []types.Query{
90 buildQuery(`CREATE TABLE t1 (k INT, v TEXT, PRIMARY KEY(k))`),
91 })
92 _, _, err = st1.Query(req, true)
93 So(err, ShouldNotBeNil)
94 err = errors.Cause(err)
95 So(err, ShouldNotBeNil)
96 So(err, ShouldEqual, sql.ErrTxDone)
97 })
98 })
99 Convey("The state will report error on read with uncommitted schema change", func() {
100 var (

Callers

nothing calls this directly

Calls 15

DatabaseIDTypeAlias · 0.92
QueryTypeTypeAlias · 0.92
NewStateFunction · 0.85
concatFunction · 0.85
NameMethod · 0.80
ReplayMethod · 0.80
StatMethod · 0.80
getSeqMethod · 0.80
readMethod · 0.80
UpdateRespMethod · 0.80
CommitExMethod · 0.80
ReplayBlockMethod · 0.80

Tested by

no test coverage detected