Skip to content

Commit c06d859

Browse files
committed
[#23331] yugabyted: Fixing yugabyted tests broken with pg_isready diff D34597.
Summary: On Jenkins pipelines `pg_isready` binary is not available in the paths configured in yugabyted. Adding required changes to find the `pg_isready` on Jenkins VMs. Jira: DB-12256 Test Plan: ./yb_build.sh --java-test 'org.yb.yugabyted.TestYugabytedSingleNode' Reviewers: sgarg-yb Reviewed By: sgarg-yb Subscribers: yugabyted-dev Differential Revision: https://phorge.dev.yugabyte.com/D40379
1 parent 50db5f0 commit c06d859

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

bin/yugabyted

+20-17
Original file line numberDiff line numberDiff line change
@@ -479,36 +479,38 @@ def check_files_in_path(path, files):
479479

480480
return not has_error
481481

482-
def get_ysqlsh_test_env_path():
482+
def find_binary_path_in_test_env(binary_name):
483483

484-
# Find directories inside YUGABYTE_DIR containing ysqlsh
485-
directories_with_ysqlsh = find_directories_with_ysqlsh(YUGABYTE_DIR)
486-
if directories_with_ysqlsh:
487-
for directory in directories_with_ysqlsh:
484+
# Find directories inside YUGABYTE_DIR containing the specific binary.
485+
directories_with_binary = find_test_directories_with_binary(YUGABYTE_DIR, binary_name)
486+
if directories_with_binary:
487+
for directory in directories_with_binary:
488488
if 'postgres/bin' in directory:
489-
ysqlsh_path = os.path.join(directory, 'ysqlsh')
490-
Output.log("Using directory for running ysqlsh: {}".format(
489+
binary_path = os.path.join(directory, binary_name)
490+
Output.log("Using directory for running {}: {}".format(binary_name,
491491
directory))
492-
return ysqlsh_path
492+
return binary_path
493493
else:
494494
Output.log_error_and_exit(
495-
"No directories containing ysqlsh were found.")
495+
"No directories containing {} were found.".format(binary_name))
496496

497-
498-
def find_directories_with_ysqlsh(root_dir):
499-
directories_with_ysqlsh = []
497+
def find_test_directories_with_binary(root_dir, binary_name):
498+
directories_with_binary = []
500499
for dirpath, _, filenames in os.walk(root_dir):
501-
if 'ysqlsh' in filenames:
502-
directories_with_ysqlsh.append(dirpath)
503-
return directories_with_ysqlsh
500+
if binary_name in filenames:
501+
directories_with_binary.append(dirpath)
502+
return directories_with_binary
504503

505504
# Finds the path of a particular YB binary
506505
def find_binary_location(binary_name):
507506

508507
# Specific path for ysqlsh in test environment
509508
is_test_env = os.getenv('USER') == 'jenkins'
510509
if binary_name == "ysqlsh" and is_test_env:
511-
return get_ysqlsh_test_env_path()
510+
return find_binary_path_in_test_env(binary_name)
511+
512+
if binary_name == "pg_isready" and is_test_env:
513+
return find_binary_path_in_test_env(binary_name)
512514

513515
# Default if tar is downloaded
514516
dir_candidates = [
@@ -5835,8 +5837,9 @@ class ControlScript(object):
58355837

58365838
def check_pg_isready(self, timeout = 5, retries = 10):
58375839
advertise_ip = self.advertise_ip()
5840+
ysql_port = self.configs.saved_data.get("ysql_port")
58385841
path = find_binary_location("pg_isready")
5839-
cmd = [path, "-h", str(advertise_ip)]
5842+
cmd = [path, "-h", str(advertise_ip), "-p", str(ysql_port)]
58405843

58415844
(out, err, retcode) = run_process_with_retries(cmd=cmd, log_cmd=True, retries=retries,
58425845
timeout=timeout)

java/yb-yugabyted/src/test/java/org/yb/yugabyted/TestYugabytedSingleNode.java

+41-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
package org.yb.yugabyted;
22

3-
import static org.yb.AssertionWrappers.assertEquals;
4-
import static org.yb.AssertionWrappers.assertTrue;
3+
import java.io.BufferedReader;
4+
import java.io.InputStreamReader;
55
import java.util.ArrayList;
6+
import java.util.List;
67
import java.util.Map;
8+
9+
import org.json.JSONObject;
710
import org.junit.Test;
811
import org.junit.runner.RunWith;
912
import org.slf4j.Logger;
1013
import org.slf4j.LoggerFactory;
14+
import static org.yb.AssertionWrappers.assertEquals;
15+
import static org.yb.AssertionWrappers.assertTrue;
1116
import org.yb.YBTestRunner;
1217
import org.yb.minicluster.MiniYBDaemon;
1318
import org.yb.minicluster.MiniYugabytedClusterParameters;
1419
import org.yb.minicluster.MiniYugabytedNodeConfigurations;
1520
import org.yb.minicluster.YugabytedTestUtils;
1621

1722
import com.google.common.net.HostAndPort;
18-
import org.json.JSONObject;
1923

2024
@RunWith(value = YBTestRunner.class)
2125
public class TestYugabytedSingleNode extends BaseYbdClientTest {
@@ -36,6 +40,7 @@ public TestYugabytedSingleNode() {
3640

3741
clusterConfigurations.add(nodeConfigurations);
3842
}
43+
3944
}
4045

4146
@Test(timeout = 300000)
@@ -54,15 +59,47 @@ public void testSingleNode() throws Exception {
5459
JSONObject jsonObject = new JSONObject(jsonResponse);
5560
String actualClusterUuid = jsonObject.getString("cluster_uuid");
5661
LOG.info("Actual Cluster UUID: " + actualClusterUuid);
57-
String baseDir = clusterConfigurations.get(0).baseDir;
62+
String baseDir = clusterConfigurations.get(0).getBaseDir();
5863
// Assert Cluster UUIDs match
5964
assertEquals(expectedClusterUuid, actualClusterUuid);
6065

66+
// Check the ysql status
67+
assertTrue(getYsqlStatus());
68+
6169
// Assert YSQL and YCQL connection
6270
boolean isYsqlConnected = YugabytedTestUtils.testYsqlConnection(baseDir, host);
6371
boolean isYcqlConnected = YugabytedTestUtils.testYcqlConnection(baseDir, host);
6472

6573
assertTrue(isYsqlConnected);
6674
assertTrue(isYcqlConnected);
6775
}
76+
77+
78+
private Boolean getYsqlStatus() throws Exception {
79+
String baseDir = clusterConfigurations.get(0).getBaseDir();
80+
Boolean ysqlStatus = false;
81+
82+
List<String> statusCmd = YugabytedTestUtils.getYugabytedStatus(baseDir);
83+
LOG.info("Yugabyted status cmd: " + statusCmd);
84+
ProcessBuilder procBuilder =
85+
new ProcessBuilder(statusCmd).redirectErrorStream(true);
86+
Process proc = procBuilder.start();
87+
88+
try (BufferedReader reader =
89+
new BufferedReader(new InputStreamReader(proc.getInputStream()))) {
90+
String line;
91+
while ((line = reader.readLine()) != null) {
92+
LOG.info("Yugabyted lines: " + line);
93+
if (line.contains("YSQL Status") && !line.contains("Not Ready")) {
94+
ysqlStatus = true;
95+
return ysqlStatus;
96+
}
97+
}
98+
}
99+
int exitCode = proc.waitFor();
100+
if (exitCode != 0) {
101+
LOG.error("Status command failed with exit code: " + exitCode);
102+
}
103+
return ysqlStatus;
104+
}
68105
}

0 commit comments

Comments
 (0)