@@ -818,6 +818,82 @@ func TestSerializableState(t *testing.T) {
818818 })
819819 }
820820 })
821+ Convey ("The state should see changes" , FailureContinues , func (c C ) {
822+ // Build transaction query
823+ var (
824+ count = 1000
825+ queries = make ([]types.Query , count + 2 )
826+ req * types.Request
827+ )
828+ queries [0 ] = buildQuery (`BEGIN` )
829+ for i := 0 ; i < count ; i ++ {
830+ queries [i + 1 ] = buildQuery (
831+ `INSERT INTO t1(k, v) VALUES (?, ?)` , i , fmt .Sprintf ("v%d" , i ),
832+ )
833+ }
834+ queries [count + 1 ] = buildQuery (`COMMIT` )
835+ req = buildRequest (types .WriteQuery , queries )
836+ // Send uncommitted transaction on background
837+ var _ , resp , err = state .Query (req , true )
838+ c .So (err , ShouldBeNil )
839+ c .So (resp .Header .RowCount , ShouldEqual , 0 )
840+
841+ // Test isolation level
842+ for i := 0 ; i < count ; i ++ {
843+ _ , resp , err = state .Query (buildRequest (types .ReadQuery , []types.Query {
844+ buildQuery (`SELECT COUNT(1) AS cnt FROM t1` ),
845+ }), true )
846+ So (resp .Payload , ShouldResemble , types.ResponsePayload {
847+ Columns : []string {"cnt" },
848+ DeclTypes : []string {"" },
849+ Rows : []types.ResponseRow {{Values : []interface {}{int64 (count )}}},
850+ })
851+ }
852+
853+ req = buildRequest (types .WriteQuery , []types.Query {
854+ buildQuery ("DELETE FROM t1" ),
855+ })
856+ _ , resp , err = state .Query (req , true )
857+ c .So (err , ShouldBeNil )
858+ })
859+ Convey ("The state should not see changes because of failure query content" , FailureContinues , func (c C ) {
860+ // Build transaction query
861+ var (
862+ count = 1000
863+ queries = make ([]types.Query , count + 3 )
864+ req * types.Request
865+ )
866+ queries [0 ] = buildQuery (`BEGIN` )
867+ for i := 0 ; i < count ; i ++ {
868+ queries [i + 1 ] = buildQuery (
869+ `INSERT INTO t1(k, v) VALUES (?, ?)` , i , fmt .Sprintf ("v%d" , i ),
870+ )
871+ }
872+ queries [count + 1 ] = buildQuery (`HAHA` )
873+ queries [count + 2 ] = buildQuery (`COMMIT` )
874+ req = buildRequest (types .WriteQuery , queries )
875+ // Send uncommitted transaction on background
876+ var _ , resp , err = state .Query (req , true )
877+ c .So (err , ShouldNotBeNil )
878+
879+ // Test isolation level
880+ for i := 0 ; i < count ; i ++ {
881+ _ , resp , err = state .Query (buildRequest (types .ReadQuery , []types.Query {
882+ buildQuery (`SELECT COUNT(1) AS cnt FROM t1` ),
883+ }), true )
884+ So (resp .Payload , ShouldResemble , types.ResponsePayload {
885+ Columns : []string {"cnt" },
886+ DeclTypes : []string {"" },
887+ Rows : []types.ResponseRow {{Values : []interface {}{int64 (0 )}}},
888+ })
889+ }
890+
891+ req = buildRequest (types .WriteQuery , []types.Query {
892+ buildQuery ("DELETE FROM t1" ),
893+ })
894+ _ , resp , err = state .Query (req , true )
895+ c .So (err , ShouldBeNil )
896+ })
821897 })
822898 })
823899}
0 commit comments