MCPcopy Create free account
hub / github.com/apache/arrow / GcsTestbench

Method GcsTestbench

cpp/src/arrow/filesystem/gcsfs_test.cc:68–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66class GcsTestbench : public ::testing::Environment {
67 public:
68 GcsTestbench() {
69 port_ = std::to_string(GetListenPort());
70 auto error = std::string("Could not start GCS emulator 'storage-testbench'");
71 auto server_process = std::make_unique<util::Process>();
72 auto status = server_process->SetExecutable("storage-testbench");
73 if (!status.ok()) {
74 error += ": " + status.ToString();
75 error_ = std::move(error);
76 return;
77 }
78
79 server_process->SetArgs({"--port", port_});
80 // Keep stderr so that startup failures are visible in the test log.
81 status = server_process->Execute();
82 if (!status.ok()) {
83 error += ": " + status.ToString();
84 error_ = std::move(error);
85 return;
86 }
87
88 // The testbench may accept connections well before it answers requests,
89 // so poll with a per-attempt budget shorter than the overall one.
90 auto testbench_is_running = [&server_process, this]() {
91 auto ready_timeout = std::chrono::seconds(60);
92 auto attempt_timeout = std::chrono::seconds(5);
93 std::chrono::time_point<std::chrono::steady_clock> end =
94 std::chrono::steady_clock::now() + ready_timeout;
95 while (server_process->IsRunning() && std::chrono::steady_clock::now() < end) {
96 auto client = gcs::Client(
97 google::cloud::Options{}
98 .set<gcs::RestEndpointOption>("http://127.0.0.1:" + port_)
99 .set<gc::UnifiedCredentialsOption>(gc::MakeInsecureCredentials())
100 .set<gcs::RetryPolicyOption>(
101 gcs::LimitedTimeRetryPolicy(attempt_timeout).clone()));
102 auto metadata = client.GetBucketMetadata("nonexistent");
103 if (metadata.status().code() == google::cloud::StatusCode::kNotFound) {
104 return true;
105 }
106 }
107 return false;
108 };
109
110 if (!testbench_is_running()) {
111 error += " (did not become ready)";
112 error_ = std::move(error);
113 return;
114 }
115
116 server_process_ = std::move(server_process);
117 }
118
119 bool running() { return server_process_ && server_process_->IsRunning(); }
120

Callers

nothing calls this directly

Calls 12

to_stringFunction · 0.85
GetListenPortFunction · 0.85
cloneMethod · 0.80
ClientClass · 0.50
SetExecutableMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45
SetArgsMethod · 0.45
ExecuteMethod · 0.45
IsRunningMethod · 0.45
codeMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected