@@ -776,8 +776,8 @@ defmodule TransactionTest do
776
776
test "transaction logs begin :commit and :rollback" do
777
777
stack = [
778
778
{ :ok , :state } ,
779
- { :commit , :new_state } ,
780
- { :rollback , :newer_state } ,
779
+ { :transaction , :new_state } ,
780
+ { :error , :newer_state } ,
781
781
]
782
782
{ :ok , agent } = A . start_link ( stack )
783
783
@@ -791,7 +791,7 @@ defmodule TransactionTest do
791
791
[ log: log ] ) == { :error , :rollback }
792
792
793
793
assert_received % DBConnection.LogEntry { call: :begin } = entry
794
- err = DBConnection.TransactionError . exception ( :commit )
794
+ err = DBConnection.TransactionError . exception ( :transaction )
795
795
assert % { query: :begin , params: nil , result: { :error , ^ err } } = entry
796
796
assert is_integer ( entry . pool_time )
797
797
assert entry . pool_time >= 0
@@ -805,7 +805,7 @@ defmodule TransactionTest do
805
805
[ log: log ] ) == { :error , :rollback }
806
806
807
807
assert_received % DBConnection.LogEntry { call: :begin } = entry
808
- err = DBConnection.TransactionError . exception ( :rollback )
808
+ err = DBConnection.TransactionError . exception ( :error )
809
809
assert % { query: :begin , params: nil , result: { :error , ^ err } } = entry
810
810
assert is_integer ( entry . pool_time )
811
811
assert entry . pool_time >= 0
@@ -825,9 +825,9 @@ defmodule TransactionTest do
825
825
stack = [
826
826
{ :ok , :state } ,
827
827
{ :ok , :began , :new_state } ,
828
- { :begin , :newer_state } ,
828
+ { :idle , :newer_state } ,
829
829
{ :ok , :began , :newest_state } ,
830
- { :rollback , :state2 } ,
830
+ { :error , :state2 } ,
831
831
{ :ok , :rolledback , :new_state2 }
832
832
]
833
833
{ :ok , agent } = A . start_link ( stack )
@@ -843,7 +843,7 @@ defmodule TransactionTest do
843
843
[ log: log ] ) == { :error , :rollback }
844
844
845
845
assert_received % DBConnection.LogEntry { call: :commit } = entry
846
- err = DBConnection.TransactionError . exception ( :begin )
846
+ err = DBConnection.TransactionError . exception ( :idle )
847
847
assert % { query: :commit , params: nil , result: { :error , ^ err } } = entry
848
848
assert is_nil ( entry . pool_time )
849
849
assert is_integer ( entry . connection_time )
@@ -878,7 +878,7 @@ defmodule TransactionTest do
878
878
stack = [
879
879
{ :ok , :state } ,
880
880
{ :ok , :began , :new_state } ,
881
- { :begin , :newer_state }
881
+ { :idle , :newer_state }
882
882
]
883
883
{ :ok , agent } = A . start_link ( stack )
884
884
@@ -896,7 +896,7 @@ defmodule TransactionTest do
896
896
[ log: log ] ) == { :error , :oops }
897
897
898
898
assert_received % DBConnection.LogEntry { call: :rollback } = entry
899
- err = DBConnection.TransactionError . exception ( :begin )
899
+ err = DBConnection.TransactionError . exception ( :idle )
900
900
assert % { query: :rollback , params: nil , result: { :error , ^ err } } = entry
901
901
assert is_nil ( entry . pool_time )
902
902
assert is_integer ( entry . connection_time )
@@ -953,4 +953,44 @@ defmodule TransactionTest do
953
953
handle_begin: [ _ , :state2 ] ,
954
954
handle_rollback: [ _ , :new_state2 ] ] = A . record ( agent )
955
955
end
956
+
957
+ test "status returns result" do
958
+ err = RuntimeError . exception ( "oops" )
959
+ stack = [
960
+ { :ok , :state } ,
961
+ { :idle , :new_state } ,
962
+ { :transaction , :newer_state } ,
963
+ { :error , :newest_state } ,
964
+ { :disconnect , err , :state2 } ,
965
+ :ok ,
966
+ fn ( opts ) ->
967
+ send ( opts [ :parent ] , :reconnected )
968
+ { :ok , :new_state2 }
969
+ end ,
970
+ ]
971
+ { :ok , agent } = A . start_link ( stack )
972
+
973
+ opts = [ agent: agent , parent: self ( ) ]
974
+ { :ok , pool } = P . start_link ( opts )
975
+
976
+ assert P . status ( pool , opts ) == :idle
977
+ assert P . status ( pool , opts ) == :transaction
978
+ assert P . run ( pool , fn ( conn ) ->
979
+ assert P . status ( pool , [ queue: false ] ++ opts ) == :error
980
+ assert P . status ( conn , opts )
981
+ end , opts )
982
+ assert P . status ( pool , opts ) == :error
983
+
984
+ assert_receive :reconnected
985
+
986
+ assert [
987
+ connect: [ _ ] ,
988
+ handle_status: [ _ , :state ] ,
989
+ handle_status: [ _ , :new_state ] ,
990
+ handle_status: [ _ , :newer_state ] ,
991
+ handle_status: [ _ , :newest_state ] ,
992
+ disconnect: [ ^ err , :state2 ] ,
993
+ connect: [ _ ]
994
+ ] = A . record ( agent )
995
+ end
956
996
end
0 commit comments