Skip to content

Commit

Permalink
Merge pull request trilogy-libraries#89 from matthewd/build-improvements
Browse files Browse the repository at this point in the history
Build improvements
  • Loading branch information
matthewd authored Jun 8, 2023
2 parents d7da184 + 6f1cc17 commit 5a7eb6a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ EXAMPLES = example/trilogy_query

UNAME_S := $(shell uname -s)

ifneq ($(UNAME_S), Darwin)
ifeq ($(UNAME_S), Darwin)
CFLAGS += "-I$(shell brew --prefix [email protected])/include"
LDFLAGS += "-L$(shell brew --prefix [email protected])/lib"
else
CFLAGS += -fPIC
LDFLAGS += -pie -Wl,-z,relro,-z,now
endif
Expand Down Expand Up @@ -48,7 +51,7 @@ clean:
rm -f test/test $(TEST_OBJS)

test/test: $(TEST_SOURCES) libtrilogy.a
$(CC) $(CFLAGS) $(LDFLAGS) -o test/test $(TEST_SOURCES) -L. -ltrilogy $(OPENSSL)
$(CC) $(CFLAGS) $(LDFLAGS) -Wno-strict-prototypes -o test/test $(TEST_SOURCES) -L. -ltrilogy $(OPENSSL)

update_greatest:
curl -o test/greatest.h https://raw.githubusercontent.com/silentbicycle/greatest/master/greatest.h
Expand Down
6 changes: 6 additions & 0 deletions contrib/ruby/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Rake::ExtensionTask.new do |ext|
ext.lib_dir = "lib/trilogy"
end

# When any of the parent library's files change, we need to re-run extconf
vendored_c_lib = FileList["ext/trilogy-ruby/src/**/*.c", "ext/trilogy-ruby/inc/**/*.h"]
if extconf_task = Rake.application.tasks.find { |t| t.name =~ /Makefile/ }
task extconf_task => vendored_c_lib
end

Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/*_test.rb']
Expand Down
20 changes: 6 additions & 14 deletions contrib/ruby/test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,9 @@ def test_cast_exception_during_query_does_not_close_the_connection
end
assert_equal "Invalid date: 1234-00-00 00:00:00", err.message

err = assert_raises Trilogy::Error do
assert_raises_connection_error do
client.ping
end
assert_includes err.message, "TRILOGY_CLOSED_CONNECTION"
end

def test_client_side_timeout_checks_result_set
Expand All @@ -587,11 +586,9 @@ def test_client_side_timeout_checks_result_set
end
end

err = assert_raises Trilogy::Error do
assert_raises_connection_error do
client.query("SELECT varchar_test FROM trilogy_test WHERE int_test = 2").to_a
end

assert_includes err.message, "TRILOGY_CLOSED_CONNECTION"
end

def assert_elapsed(expected, delta)
Expand All @@ -611,11 +608,9 @@ def test_timeout_deadlines
end
end

err = assert_raises Trilogy::Error do
assert_raises_connection_error do
client.query("SELECT 'hello'").to_a
end

assert_includes err.message, "TRILOGY_CLOSED_CONNECTION"
end
end

Expand Down Expand Up @@ -684,11 +679,9 @@ def test_releases_gvl
end
end

err = assert_raises Trilogy::Error do
assert_raises_connection_error do
client.ping
end

assert_includes err.message, "TRILOGY_CLOSED_CONNECTION"
end

USR1 = Class.new(StandardError)
Expand Down Expand Up @@ -832,7 +825,7 @@ def test_configured_max_packet_above_server

assert_equal "trilogy_query_send: TRILOGY_MAX_PACKET_EXCEEDED", exception.message

exception = assert_raises Trilogy::QueryError do
exception = assert_raises_connection_error do
client.query query_for_target_packet_size(24 * 1024 * 1024 + 1)
end

Expand Down Expand Up @@ -997,10 +990,9 @@ def test_close_terminate_parent_connection
_, status = Process.wait2(pid)
assert_predicate status, :success?

error = assert_raises Trilogy::QueryError do
assert_raises_connection_error do
client.query("SELECT 1")
end
assert_match "TRILOGY_CLOSED_CONNECTION", error.message
end

def test_discard_doesnt_terminate_parent_connection
Expand Down
4 changes: 1 addition & 3 deletions contrib/ruby/test/ssl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ def test_raise_proper_invalid_ssl_state
assert_includes err.message, "SSL Error"

# Socket is closed on this attempt due to previous failures.
err = assert_raises Trilogy::Error do
assert_raises_connection_error do
client.query "SELECT 1"
end
assert_includes err.message, "TRILOGY_CLOSED_CONNECTION"

ensure
Process.kill("QUIT", pid)
Expand Down Expand Up @@ -237,5 +236,4 @@ def test_trilogy_ssl_client_key_and_cert_match
ensure
ensure_closed client
end

end
12 changes: 12 additions & 0 deletions contrib/ruby/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ def create_test_table(client)

client.query sql
end

def assert_raises_connection_error(&block)
err = assert_raises(Trilogy::Error, &block)

if err.is_a?(Trilogy::QueryError)
assert_includes err.message, "TRILOGY_CLOSED_CONNECTION"
else
assert_instance_of Trilogy::ConnectionResetError, err
end

err
end
end

0 comments on commit 5a7eb6a

Please sign in to comment.