From de31de970af4a69757cb8bab1723ccaca714747f Mon Sep 17 00:00:00 2001 From: Mamiko Ino Date: Wed, 16 Sep 2026 15:09:22 +0900 Subject: [PATCH 1/7] Reuse a Faraday client per Trino::Client instance --- lib/trino/client/client.rb | 9 +++++---- lib/trino/client/faraday_client.rb | 2 +- lib/trino/client/query.rb | 15 +++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/trino/client/client.rb b/lib/trino/client/client.rb index b5d48825..a8add3b5 100644 --- a/lib/trino/client/client.rb +++ b/lib/trino/client/client.rb @@ -21,10 +21,11 @@ module Trino::Client class Client def initialize(options) @options = options + @faraday = Trino::Client.faraday_client(options) end def query(query, &block) - q = Query.start(query, @options) + q = Query.start(query, @faraday, @options) if block begin yield q @@ -37,15 +38,15 @@ def query(query, &block) end def resume_query(next_uri) - return Query.resume(next_uri, @options) + return Query.resume(next_uri, @faraday, @options) end def kill(query_id) - return Query.kill(query_id, @options) + return Query.kill(query_id, @faraday, @options) end def run(query) - q = Query.start(query, @options) + q = Query.start(query, @faraday, @options) begin columns = q.columns if columns.empty? diff --git a/lib/trino/client/faraday_client.rb b/lib/trino/client/faraday_client.rb index 1be8037f..023bfd1f 100644 --- a/lib/trino/client/faraday_client.rb +++ b/lib/trino/client/faraday_client.rb @@ -92,7 +92,7 @@ def self.faraday_client(options) faraday.request :gzip end faraday.response :logger, options[:http_debug_logger] if options[:http_debug] - faraday.adapter Faraday.default_adapter + faraday.adapter(options[:faraday_adapter] || Faraday.default_adapter) end faraday.headers.merge!(HEADERS) diff --git a/lib/trino/client/query.rb b/lib/trino/client/query.rb index 8b94f325..767d9d0c 100644 --- a/lib/trino/client/query.rb +++ b/lib/trino/client/query.rb @@ -25,26 +25,21 @@ module Trino::Client require 'trino/client/statement_client' class Query - def self.start(query, options) - new StatementClient.new(faraday_client(options), query, options) + def self.start(query, faraday, options) + new StatementClient.new(faraday, query, options) end - def self.resume(next_uri, options) - new StatementClient.new(faraday_client(options), nil, options, next_uri) + def self.resume(next_uri, faraday, options) + new StatementClient.new(faraday, nil, options, next_uri) end - def self.kill(query_id, options) - faraday = faraday_client(options) + def self.kill(query_id, faraday, options) response = faraday.delete do |req| req.url "/v1/query/#{query_id}" end return response.status / 100 == 2 end - def self.faraday_client(options) - Trino::Client.faraday_client(options) - end - def self.transform_row(column_value_parsers, row) row_object = {} From aca8018c60f36aef15c415e6414f065fd6dacd1b Mon Sep 17 00:00:00 2001 From: Mamiko Ino Date: Wed, 16 Sep 2026 15:49:17 +0900 Subject: [PATCH 2/7] Add tests for Faraday client reuse and adapter selection --- lib/trino/client/client.rb | 2 +- lib/trino/client/query.rb | 2 +- spec/client_spec.rb | 123 +++++++++++++++++++++++++++++++++- spec/query_spec.rb | 86 ++++++++++++++++++++++++ spec/statement_client_spec.rb | 39 ++++++++--- 5 files changed, 241 insertions(+), 11 deletions(-) create mode 100644 spec/query_spec.rb diff --git a/lib/trino/client/client.rb b/lib/trino/client/client.rb index a8add3b5..024745fd 100644 --- a/lib/trino/client/client.rb +++ b/lib/trino/client/client.rb @@ -42,7 +42,7 @@ def resume_query(next_uri) end def kill(query_id) - return Query.kill(query_id, @faraday, @options) + return Query.kill(query_id, @faraday) end def run(query) diff --git a/lib/trino/client/query.rb b/lib/trino/client/query.rb index 767d9d0c..aaa2f4af 100644 --- a/lib/trino/client/query.rb +++ b/lib/trino/client/query.rb @@ -33,7 +33,7 @@ def self.resume(next_uri, faraday, options) new StatementClient.new(faraday, nil, options, next_uri) end - def self.kill(query_id, faraday, options) + def self.kill(query_id, faraday) response = faraday.delete do |req| req.url "/v1/query/#{query_id}" end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 41196caa..7c9a0b24 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -1,7 +1,128 @@ require 'spec_helper' describe Trino::Client::Client do - let(:client) { Trino::Client.new({}) } + let(:client) do + Trino::Client.new(server: "localhost:8080") + end + + describe "Faraday client reuse" do + let(:options) do + { + server: "localhost:8080", + user: "test-user" + } + end + + let(:faraday) do + instance_double(Faraday::Connection) + end + + before do + allow(Trino::Client) + .to receive(:faraday_client) + .with(options) + .and_return(faraday) + end + + it "creates one Faraday client per Client instance" do + expect(Trino::Client) + .to receive(:faraday_client) + .with(options) + .once + .and_return(faraday) + + described_class.new(options) + end + + it "reuses the same Faraday client for multiple queries" do + client = described_class.new(options) + first_query = instance_double(Trino::Client::Query) + second_query = instance_double(Trino::Client::Query) + + expect(Trino::Client::Query) + .to receive(:start) + .with("select 1", faraday, options) + .and_return(first_query) + + expect(Trino::Client::Query) + .to receive(:start) + .with("select 2", faraday, options) + .and_return(second_query) + + expect(client.query("select 1")).to eq(first_query) + expect(client.query("select 2")).to eq(second_query) + end + + it "reuses the same Faraday client when running a query" do + client = described_class.new(options) + query = instance_double( + Trino::Client::Query, + columns: [], + close: nil + ) + + expect(Trino::Client::Query) + .to receive(:start) + .with("select 1", faraday, options) + .and_return(query) + + expect(client.run("select 1")).to eq([[], []]) + end + + it "reuses the same Faraday client when resuming a query" do + client = described_class.new(options) + query = instance_double(Trino::Client::Query) + next_uri = "http://localhost:8080/v1/statement/next" + + expect(Trino::Client::Query) + .to receive(:resume) + .with(next_uri, faraday, options) + .and_return(query) + + expect(client.resume_query(next_uri)).to eq(query) + end + + it "reuses the same Faraday client when killing a query" do + client = described_class.new(options) + + expect(Trino::Client::Query) + .to receive(:kill) + .with("query-id", faraday) + .and_return(true) + + expect(client.kill("query-id")).to eq(true) + end + + it "creates a separate Faraday client for each Client instance" do + first_faraday = instance_double(Faraday::Connection) + second_faraday = instance_double(Faraday::Connection) + + expect(Trino::Client) + .to receive(:faraday_client) + .with(options) + .twice + .and_return(first_faraday, second_faraday) + + first_client = described_class.new(options) + second_client = described_class.new(options) + + first_query = instance_double(Trino::Client::Query) + second_query = instance_double(Trino::Client::Query) + + expect(Trino::Client::Query) + .to receive(:start) + .with("select 1", first_faraday, options) + .and_return(first_query) + + expect(Trino::Client::Query) + .to receive(:start) + .with("select 2", second_faraday, options) + .and_return(second_query) + + first_client.query("select 1") + second_client.query("select 2") + end + end describe 'rehashes' do let(:columns) do diff --git a/spec/query_spec.rb b/spec/query_spec.rb new file mode 100644 index 00000000..e0f8161f --- /dev/null +++ b/spec/query_spec.rb @@ -0,0 +1,86 @@ +require "spec_helper" + +describe Trino::Client::Query do + let(:faraday) do + instance_double(Faraday::Connection) + end + + let(:options) do + { + server: "localhost:8080", + user: "test-user" + } + end + + describe ".start" do + it "passes the provided Faraday client to StatementClient" do + statement_client = + instance_double(Trino::Client::StatementClient) + + expect(Trino::Client::StatementClient) + .to receive(:new) + .with(faraday, "select 1", options) + .and_return(statement_client) + + query = described_class.start("select 1", faraday, options) + + expect(query).to be_a(described_class) + end + end + + describe ".resume" do + it "passes the provided Faraday client and next URI to StatementClient" do + statement_client = + instance_double(Trino::Client::StatementClient) + + next_uri = "http://localhost:8080/v1/statement/next" + + expect(Trino::Client::StatementClient) + .to receive(:new) + .with(faraday, nil, options, next_uri) + .and_return(statement_client) + + query = described_class.resume(next_uri, faraday, options) + + expect(query).to be_a(described_class) + end + end + + describe ".kill" do + it "uses the provided Faraday client to delete the query" do + request = double("request") + response = instance_double(Faraday::Response, status: 204) + + expect(faraday) + .to receive(:delete) + .and_yield(request) + .and_return(response) + + expect(request) + .to receive(:url) + .with("/v1/query/query-id") + + result = described_class.kill("query-id", faraday) + + expect(result).to eq(true) + end + + it "returns false when deleting the query fails" do + request = double("request") + response = instance_double(Faraday::Response, status: 500) + + allow(request) + .to receive(:url) + .with("/v1/query/query-id") + + allow(faraday) + .to receive(:delete) + .and_yield(request) + .and_return(response) + + result = described_class.kill("query-id", faraday) + + expect(result).to eq(false) + end + end +end \ No newline at end of file diff --git a/spec/statement_client_spec.rb b/spec/statement_client_spec.rb index b2895bec..26c0f769 100644 --- a/spec/statement_client_spec.rb +++ b/spec/statement_client_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'faraday/adapter/test' describe Trino::Client::StatementClient do let :options do @@ -442,7 +443,7 @@ it "forbids using basic auth when ssl is disabled" do expect do - Query.__send__(:faraday_client, { + Trino::Client.faraday_client({ server: 'localhost', password: 'abcd' }) @@ -488,16 +489,38 @@ end end + describe "faraday adapter" do + it "uses the adapter specified in the options" do + connection = Trino::Client.faraday_client( + server: "localhost", + faraday_adapter: :test + ) + + expect(connection.adapter).to eq(Faraday::Adapter::Test) + end + + it "uses the default adapter when no adapter is specified" do + connection = Trino::Client.faraday_client( + server: "localhost" + ) + + expected_adapter = + Faraday::Adapter.lookup_middleware(Faraday.default_adapter) + + expect(connection.adapter).to eq(expected_adapter) + end + end + describe "ssl" do it "is disabled by default" do - f = Query.__send__(:faraday_client, { + f = Trino::Client.faraday_client({ server: "localhost", }) expect(f.url_prefix.to_s).to eq "http://localhost/" end it "is enabled with ssl: true" do - f = Query.__send__(:faraday_client, { + f = Trino::Client.faraday_client({ server: "localhost", ssl: true, }) @@ -506,7 +529,7 @@ end it "is enabled with ssl: {verify: false}" do - f = Query.__send__(:faraday_client, { + f = Trino::Client.faraday_client({ server: "localhost", ssl: {verify: false} }) @@ -516,7 +539,7 @@ it "rejects invalid ssl: verify: object" do expect do - f = Query.__send__(:faraday_client, { + f = Trino::Client.faraday_client({ server: "localhost", ssl: {verify: "??"} }) @@ -534,7 +557,7 @@ client_key: OpenSSL::PKey::DSA.new, } - f = Query.__send__(:faraday_client, { + f = Trino::Client.faraday_client({ server: "localhost", ssl: ssl, }) @@ -550,7 +573,7 @@ it "rejects an invalid string" do expect do - Query.__send__(:faraday_client, { + Trino::Client.faraday_client({ server: "localhost", ssl: '??', }) @@ -559,7 +582,7 @@ it "rejects an integer" do expect do - Query.__send__(:faraday_client, { + Trino::Client.faraday_client({ server: "localhost", ssl: 3, }) From 40284c9bfbc770f227bff354a0dc201806826156 Mon Sep 17 00:00:00 2001 From: Mamiko Ino Date: Thu, 17 Sep 2026 09:03:10 +0900 Subject: [PATCH 3/7] Preserve query-specific headers with connection reuse --- lib/trino/client/client.rb | 2 +- lib/trino/client/faraday_client.rb | 48 +++++++-------- lib/trino/client/query.rb | 5 +- lib/trino/client/statement_client.rb | 8 ++- spec/client_spec.rb | 2 +- spec/query_spec.rb | 12 ++-- spec/statement_client_spec.rb | 89 ++++++++++++++++++++++++++++ 7 files changed, 133 insertions(+), 33 deletions(-) diff --git a/lib/trino/client/client.rb b/lib/trino/client/client.rb index 024745fd..a8add3b5 100644 --- a/lib/trino/client/client.rb +++ b/lib/trino/client/client.rb @@ -42,7 +42,7 @@ def resume_query(next_uri) end def kill(query_id) - return Query.kill(query_id, @faraday) + return Query.kill(query_id, @faraday, @options) end def run(query) diff --git a/lib/trino/client/faraday_client.rb b/lib/trino/client/faraday_client.rb index 023bfd1f..d39ba6ba 100644 --- a/lib/trino/client/faraday_client.rb +++ b/lib/trino/client/faraday_client.rb @@ -14,9 +14,8 @@ # limitations under the License. # module Trino::Client - FARADAY1_USED = Faraday::VERSION.start_with?("1.") - private_constant :FARADAY1_USED + require 'base64' require 'cgi' module TrinoHeaders @@ -77,14 +76,6 @@ def self.faraday_client(options) faraday_options[:ssl] = ssl if ssl faraday = Faraday.new(faraday_options) do |faraday| - if options[:user] && options[:password] - # https://lostisland.github.io/faraday/middleware/authentication - if FARADAY1_USED - faraday.request(:basic_auth, options[:user], options[:password]) - else - faraday.request :authorization, :basic, options[:user], options[:password] - end - end if options[:follow_redirect] faraday.response :follow_redirects end @@ -96,7 +87,6 @@ def self.faraday_client(options) end faraday.headers.merge!(HEADERS) - faraday.headers.merge!(optional_headers(options)) return faraday end @@ -129,71 +119,79 @@ def self.faraday_ssl_options(options) return ssl end - def self.optional_headers(options) - usePrestoHeader = false - if options[:model_version] && options[:model_version] < 351 - usePrestoHeader = true + def self.build_query_headers(options) + use_presto_headers = false + if options[:model_version] && options[:model_version].to_i < 351 + use_presto_headers = true end headers = {} + + if options[:user] && options[:password] + credentials = Base64.strict_encode64( + "#{options[:user]}:#{options[:password]}" + ) + headers["Authorization"] = "Basic #{credentials}" + end + if v = options[:user] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_USER] = v else headers[TrinoHeaders::TRINO_USER] = v end end if v = options[:source] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_SOURCE] = v else headers[TrinoHeaders::TRINO_SOURCE] = v end end if v = options[:catalog] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_CATALOG] = v else headers[TrinoHeaders::TRINO_CATALOG] = v end end if v = options[:schema] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_SCHEMA] = v else headers[TrinoHeaders::TRINO_SCHEMA] = v end end if v = options[:time_zone] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_TIME_ZONE] = v else headers[TrinoHeaders::TRINO_TIME_ZONE] = v end end if v = options[:language] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_LANGUAGE] = v else headers[TrinoHeaders::TRINO_LANGUAGE] = v end end if v = options[:properties] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_SESSION] = encode_properties(v) else headers[TrinoHeaders::TRINO_SESSION] = encode_properties(v) end end if v = options[:client_info] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_CLIENT_INFO] = encode_client_info(v) else headers[TrinoHeaders::TRINO_CLIENT_INFO] = encode_client_info(v) end end if v = options[:client_tags] - if usePrestoHeader + if use_presto_headers headers[PrestoHeaders::PRESTO_CLIENT_TAGS] = encode_client_tags(v) else headers[TrinoHeaders::TRINO_CLIENT_TAGS] = encode_client_tags(v) @@ -245,6 +243,6 @@ def self.encode_client_tags(tags) Array(tags).join(",") end - private_class_method :faraday_ssl_options, :optional_headers, :encode_properties, :encode_client_info, :encode_client_tags + private_class_method :faraday_ssl_options, :encode_properties, :encode_client_info, :encode_client_tags end diff --git a/lib/trino/client/query.rb b/lib/trino/client/query.rb index aaa2f4af..fad15857 100644 --- a/lib/trino/client/query.rb +++ b/lib/trino/client/query.rb @@ -33,8 +33,11 @@ def self.resume(next_uri, faraday, options) new StatementClient.new(faraday, nil, options, next_uri) end - def self.kill(query_id, faraday) + def self.kill(query_id, faraday, options) response = faraday.delete do |req| + req.headers.merge!( + Trino::Client.build_query_headers(options) + ) req.url "/v1/query/#{query_id}" end return response.status / 100 == 2 diff --git a/lib/trino/client/statement_client.rb b/lib/trino/client/statement_client.rb index da9c32db..096835f1 100644 --- a/lib/trino/client/statement_client.rb +++ b/lib/trino/client/statement_client.rb @@ -30,6 +30,7 @@ class StatementClient def initialize(faraday, query, options, next_uri=nil) @faraday = faraday + @headers = Trino::Client.build_query_headers(options) @options = options @query = query @@ -72,6 +73,7 @@ def post_query_request! begin r = @faraday.post do |req| req.url uri + req.headers.merge!(@headers) req.body = @query init_request(req) @@ -229,7 +231,9 @@ def with_retry_loop def faraday_get_with_retry(uri) with_retry_loop do begin - response = @faraday.get(uri) + response = @faraday.get(uri) do |req| + req.headers.merge!(@headers) + end rescue Faraday::TimeoutError, Faraday::ConnectionFailed throw :retry_with_backoff rescue => e @@ -278,6 +282,7 @@ def raise_timeout_error! def cancel_leaf_stage if uri = @results.partial_cancel_uri @faraday.delete do |req| + req.headers.merge!(@headers) req.url uri end end @@ -291,6 +296,7 @@ def close begin if uri = @results.next_uri @faraday.delete do |req| + req.headers.merge!(@headers) req.url uri end end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 7c9a0b24..972922c7 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -87,7 +87,7 @@ expect(Trino::Client::Query) .to receive(:kill) - .with("query-id", faraday) + .with("query-id", faraday, options) .and_return(true) expect(client.kill("query-id")).to eq(true) diff --git a/spec/query_spec.rb b/spec/query_spec.rb index e0f8161f..351d1dcb 100644 --- a/spec/query_spec.rb +++ b/spec/query_spec.rb @@ -48,7 +48,8 @@ describe ".kill" do it "uses the provided Faraday client to delete the query" do - request = double("request") + request_headers = {} + request = double("request", headers: request_headers) response = instance_double(Faraday::Response, status: 204) expect(faraday) @@ -60,13 +61,16 @@ .to receive(:url) .with("/v1/query/query-id") - result = described_class.kill("query-id", faraday) + result = described_class.kill("query-id", faraday, options) + expect(request_headers).to include( + "X-Trino-User" => "test-user" + ) expect(result).to eq(true) end it "returns false when deleting the query fails" do - request = double("request") + request = double("request", headers: {}) response = instance_double(Faraday::Response, status: 500) allow(request) @@ -78,7 +82,7 @@ .and_yield(request) .and_return(response) - result = described_class.kill("query-id", faraday) + result = described_class.kill("query-id", faraday, options) expect(result).to eq(false) end diff --git a/spec/statement_client_spec.rb b/spec/statement_client_spec.rb index 26c0f769..0d4ccab2 100644 --- a/spec/statement_client_spec.rb +++ b/spec/statement_client_spec.rb @@ -163,6 +163,95 @@ end end + describe "Faraday client reuse" do + it "builds headers from the current options for each query" do + connection = Trino::Client.faraday_client(options) + + first_request = stub_request( + :post, + "http://localhost/v1/statement" + ).with( + body: query, + headers: { + "X-Trino-Catalog" => "native" + } + ).to_return( + body: response_json.to_json + ) + + described_class.new(connection, query, options) + + options[:catalog] = "updated-catalog" + + second_request = stub_request( + :post, + "http://localhost/v1/statement" + ).with( + body: query, + headers: { + "X-Trino-Catalog" => "updated-catalog" + } + ).to_return( + body: response_json.to_json + ) + + described_class.new(connection, query, options) + + expect(first_request).to have_been_requested.once + expect(second_request).to have_been_requested.once + end + + it "uses the same headers for all requests in a query" do + connection = Trino::Client.faraday_client(options) + + query_options = options.merge( + catalog: "query-catalog" + ) + + first_response = { + id: "queryid", + nextUri: "http://localhost/v1/next_uri", + stats: {} + } + + post_request = stub_request( + :post, + "http://localhost/v1/statement" + ).with( + body: query, + headers: { + "X-Trino-Catalog" => "query-catalog" + } + ).to_return( + body: first_response.to_json + ) + + get_request = stub_request( + :get, + "http://localhost/v1/next_uri" + ).with( + headers: { + "X-Trino-Catalog" => "query-catalog" + } + ).to_return( + body: response_json.to_json + ) + + statement_client = described_class.new( + connection, + query, + query_options + ) + + query_options[:catalog] = "changed-during-query" + + statement_client.advance + + expect(post_request).to have_been_requested.once + expect(get_request).to have_been_requested.once + end + end + describe "POST /v1/statement retry" do let :headers do { From f61ba2b3e58b76f663672148a49bd59273e86845 Mon Sep 17 00:00:00 2001 From: Mamiko Ino Date: Thu, 17 Sep 2026 11:37:00 +0900 Subject: [PATCH 4/7] Document the faraday_adapter option --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 146ec138..d8b27c0e 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ $ bundle exec rake modelgen:latest * **http_timeout** sets timeout in seconds to read data from a server. * **gzip** enables gzip compression. * **follow_redirect** enables HTTP redirection support. +* **faraday_adapter** sets the Faraday adapter to use. Default is `Faraday.default_adapter`. To reuse persistent HTTP connections, install` faraday-net_http_persistent` and specify `:net_http_persistent`. * **model_version** set the Trino version to which a job is submitted. Supported versions are 351, 316, 303, 0.205, 0.178, 0.173, 0.153 and 0.149. Default is 351. See [RDoc](http://www.rubydoc.info/gems/presto-client/) for the full documentation. From 078d06e80b2203f10e7aa6c4f7596046eafae89d Mon Sep 17 00:00:00 2001 From: Mamiko Ino Date: Thu, 17 Sep 2026 11:39:21 +0900 Subject: [PATCH 5/7] Test Basic authentication headers with connection reuse --- spec/statement_client_spec.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/spec/statement_client_spec.rb b/spec/statement_client_spec.rb index 0d4ccab2..503ffa38 100644 --- a/spec/statement_client_spec.rb +++ b/spec/statement_client_spec.rb @@ -164,6 +164,39 @@ end describe "Faraday client reuse" do + it "sends the Basic authorization header with each query" do + auth_options = options.merge( + ssl: true, + user: "test-user", + password: "secret" + ) + + connection = Trino::Client.faraday_client(auth_options) + + authorization = + "Basic #{Base64.strict_encode64("test-user:secret")}" + + request = stub_request( + :post, + "https://localhost/v1/statement" + ).with( + body: query, + headers: { + "Authorization" => authorization + } + ).to_return( + body: response_json.to_json + ) + + described_class.new( + connection, + query, + auth_options + ) + + expect(request).to have_been_requested.once + end + it "builds headers from the current options for each query" do connection = Trino::Client.faraday_client(options) From bebafe1cbd1918810d2be06d59cc48562e44e016 Mon Sep 17 00:00:00 2001 From: Mamiko Ino Date: Thu, 17 Sep 2026 13:24:31 +0900 Subject: [PATCH 6/7] Fix lint --- README.md | 2 +- spec/query_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d8b27c0e..018fb646 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ $ bundle exec rake modelgen:latest * **http_timeout** sets timeout in seconds to read data from a server. * **gzip** enables gzip compression. * **follow_redirect** enables HTTP redirection support. -* **faraday_adapter** sets the Faraday adapter to use. Default is `Faraday.default_adapter`. To reuse persistent HTTP connections, install` faraday-net_http_persistent` and specify `:net_http_persistent`. +* **faraday_adapter** sets the Faraday adapter to use. Default is `Faraday.default_adapter`. To reuse persistent HTTP connections, install `faraday-net_http_persistent` and specify `:net_http_persistent`. * **model_version** set the Trino version to which a job is submitted. Supported versions are 351, 316, 303, 0.205, 0.178, 0.173, 0.153 and 0.149. Default is 351. See [RDoc](http://www.rubydoc.info/gems/presto-client/) for the full documentation. diff --git a/spec/query_spec.rb b/spec/query_spec.rb index 351d1dcb..04eb329b 100644 --- a/spec/query_spec.rb +++ b/spec/query_spec.rb @@ -87,4 +87,4 @@ expect(result).to eq(false) end end -end \ No newline at end of file +end From 5e39e381f45abed069bea329a4b55c1f6162d56d Mon Sep 17 00:00:00 2001 From: Mamiko Ino Date: Thu, 17 Sep 2026 16:10:29 +0900 Subject: [PATCH 7/7] Update integration tests for Faraday client reuse --- spec/basic_query_spec.rb | 2 +- spec/gzip_spec.rb | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/spec/basic_query_spec.rb b/spec/basic_query_spec.rb index 04f8c170..745b6f58 100644 --- a/spec/basic_query_spec.rb +++ b/spec/basic_query_spec.rb @@ -51,7 +51,7 @@ it 'current query result' do @client.query('show schemas') do |q| - expect(q.current_results.info_uri).to start_with('http://localhost:8080/ui/query.html') + expect(q.current_results.info_uri).to start_with('http://localhost:8080/ui') end end diff --git a/spec/gzip_spec.rb b/spec/gzip_spec.rb index f867bb7e..7ab32488 100644 --- a/spec/gzip_spec.rb +++ b/spec/gzip_spec.rb @@ -1,12 +1,28 @@ +require 'logger' +require 'stringio' require 'spec_helper' describe Trino::Client::Client do before(:all) do @spec_path = File.dirname(__FILE__) + @http_debug_output = StringIO.new + @http_debug_logger = Logger.new(@http_debug_output) + WebMock.disable! + @cluster = TinyPresto::Cluster.new() @container = @cluster.run - @client = Trino::Client.new(server: 'localhost:8080', catalog: 'tpch', user: 'test-user', schema: 'tiny', gzip: true, http_debug: true) + + @client = Trino::Client.new( + server: 'localhost:8080', + catalog: 'tpch', + user: 'test-user', + schema: 'tiny', + gzip: true, + http_debug: true, + http_debug_logger: @http_debug_logger + ) + loop do begin # Make sure to all workers are available. @@ -17,6 +33,7 @@ sleep(3) end end + puts 'Cluster is ready' end @@ -26,15 +43,16 @@ end it 'tpch q01 with gzip option' do - $stdout = StringIO.new - begin - q = File.read("#{@spec_path}/tpch/q01.sql") - columns, rows = run_with_retry(@client, q) - expect(columns.length).to be(10) - expect(rows.length).to be(4) - expect($stdout.string).to include ('content-encoding: "gzip"') - ensure - $stdout = STDOUT - end + @http_debug_output.truncate(0) + @http_debug_output.rewind + + q = File.read("#{@spec_path}/tpch/q01.sql") + columns, rows = run_with_retry(@client, q) + + expect(columns.length).to be(10) + expect(rows.length).to be(4) + expect(@http_debug_output.string).to include( + 'content-encoding: "gzip"' + ) end end