Skip to content

Commit

Permalink
Add tests for client.session_track
Browse files Browse the repository at this point in the history
  • Loading branch information
bibstha committed Feb 7, 2020
1 parent 27b9ef9 commit 7f127dc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/mysql2/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ static VALUE rb_mysql_client_session_track(VALUE self, VALUE type) {
REQUIRE_CONNECTED(wrapper);
retVal = mysql_session_track_get_first(wrapper->client, NUM2INT(type), &data, &length);
if (retVal != 0) {
rb_raise_mysql2_error(wrapper);
return Qnil;
}
VALUE rbAry = rb_ary_new();
VALUE rbFirst = rb_str_new(data, length);
Expand Down
40 changes: 40 additions & 0 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,46 @@ def run_gc
expect(@client).to respond_to(:ping)
end

context "session_track" do
before(:each) do
@client.query("SET @@SESSION.session_track_system_variables='*';")
end

it "returns changes system variables for SESSION_TRACK_SYSTEM_VARIABLES" do
@client.query("SET @@SESSION.session_track_state_change=ON;")
res = @client.session_track(Mysql2::Client::SESSION_TRACK_SYSTEM_VARIABLES)
expect(res).to eq(["session_track_state_change", "ON"])
end

it "returns database name for SESSION_TRACK_SCHEMA" do
@client.query("USE information_schema")
res = @client.session_track(Mysql2::Client::SESSION_TRACK_SCHEMA)
expect(res).to eq(["information_schema"])
end

it "returns multiple session track type values when available" do
@client.query("SET @@SESSION.session_track_transaction_info='CHARACTERISTICS'")

res = @client.session_track(Mysql2::Client::SESSION_TRACK_TRANSACTION_STATE)
expect(res).to eq(["________"])

res = @client.session_track(Mysql2::Client::SESSION_TRACK_TRANSACTION_CHARACTERISTICS)
expect(res).to eq([""])

res = @client.session_track(Mysql2::Client::SESSION_TRACK_STATE_CHANGE)
expect(res).to be_nil

res = @client.session_track(Mysql2::Client::SESSION_TRACK_SYSTEM_VARIABLES)
expect(res).to eq(["session_track_transaction_info", "CHARACTERISTICS"])
end

it "returns empty array if session track type not found" do
@client.query("SET @@SESSION.session_track_state_change=ON;")
res = @client.session_track(Mysql2::Client::SESSION_TRACK_TRANSACTION_CHARACTERISTICS)
expect(res).to be_nil
end
end

context "select_db" do
before(:each) do
2.times do |i|
Expand Down

0 comments on commit 7f127dc

Please sign in to comment.