@@ -70,6 +70,63 @@ func Test_Transaction(t *testing.T) {
70
70
assert .Equal (t , "bookmark:1" , session .LastBookmark ())
71
71
}
72
72
73
+ var verifyFailureOnExplicitCommit = func (t * testing.T , script string ) {
74
+ stub := control .NewStubServer (t , 9001 , script )
75
+ defer stub .Finished (t )
76
+
77
+ driver := newDriver (t , "bolt://localhost:9001" )
78
+ defer driver .Close ()
79
+
80
+ session := createWriteSession (t , driver )
81
+ defer session .Close ()
82
+
83
+ tx := createTx (t , session )
84
+ defer tx .Close ()
85
+
86
+ result , err := tx .Run ("CREATE (n {name: 'Bob'})" , nil )
87
+ require .NoError (t , err )
88
+ require .NotNil (t , result )
89
+
90
+ require .False (t , result .Next ())
91
+ require .NoError (t , result .Err ())
92
+
93
+ err = tx .Commit ()
94
+ assert .Error (t , err )
95
+ assert .Contains (t , err .Error (), "unexpected connection state" )
96
+ }
97
+
98
+ var verifyFailureOnTxFuncCommit = func (t * testing.T , script string ) {
99
+ stub := control .NewStubServer (t , 9001 , script )
100
+ defer stub .Finished (t )
101
+
102
+ driver := newDriver (t , "bolt://localhost:9001" )
103
+ defer driver .Close ()
104
+
105
+ session := createWriteSession (t , driver )
106
+ defer session .Close ()
107
+
108
+ result , err := session .WriteTransaction (func (tx neo4j.Transaction ) (interface {}, error ) {
109
+ innerResult , innerErr := tx .Run ("CREATE (n {name: 'Bob'})" , nil )
110
+ require .NoError (t , innerErr )
111
+ require .NotNil (t , innerResult )
112
+ return innerResult , innerErr
113
+ })
114
+
115
+ assert .Nil (t , result )
116
+ assert .Error (t , err )
117
+ assert .Contains (t , err .Error (), "unexpected connection state" )
118
+ }
119
+
120
+ t .Run ("V1" , func (t * testing.T ) {
121
+ t .Run ("shouldFailOnConnectionFailureOnExplicitCommit" , func (t * testing.T ) {
122
+ verifyFailureOnExplicitCommit (t , path .Join ("v1" , "connection_error_on_commit.script" ))
123
+ })
124
+
125
+ t .Run ("shouldFailOnConnectionFailureOnTxFuncCommit" , func (t * testing.T ) {
126
+ verifyFailureOnTxFuncCommit (t , path .Join ("v1" , "connection_error_on_commit.script" ))
127
+ })
128
+ })
129
+
73
130
t .Run ("V3" , func (t * testing.T ) {
74
131
t .Run ("shouldExecuteSimpleQuery" , func (t * testing.T ) {
75
132
verifyReturn1 (t , path .Join ("v3" , "return_1_in_tx.script" ), nil )
@@ -83,5 +140,12 @@ func Test_Transaction(t *testing.T) {
83
140
verifyReturn1 (t , path .Join ("v3" , "begin_with_timeout.script" ), nil , neo4j .WithTxTimeout (12340 * time .Millisecond ))
84
141
})
85
142
143
+ t .Run ("shouldFailOnConnectionFailureOnExplicitCommit" , func (t * testing.T ) {
144
+ verifyFailureOnExplicitCommit (t , path .Join ("v3" , "connection_error_on_commit.script" ))
145
+ })
146
+
147
+ t .Run ("shouldFailOnConnectionFailureOnTxFuncCommit" , func (t * testing.T ) {
148
+ verifyFailureOnTxFuncCommit (t , path .Join ("v3" , "connection_error_on_commit.script" ))
149
+ })
86
150
})
87
151
}
0 commit comments