fix(tests): enhance functional test logging and adjust connection timeout
This commit is contained in:
@@ -304,6 +304,7 @@ check_PROGRAMS += tests/functionaltests/functionaltests
|
||||
tests_functionaltests_functionaltests_SOURCES = $(functionaltest_sources)
|
||||
tests_functionaltests_functionaltests_CPPFLAGS = -Itests/
|
||||
tests_functionaltests_functionaltests_CFLAGS = $(AM_CFLAGS) -I/usr/include/tcl8.6 -I/usr/include/tcl8.5
|
||||
tests_functionaltests_functionaltests_LDFLAGS = -L$(top_srcdir)/external/stabber/.libs -Wl,-rpath,$(top_srcdir)/external/stabber/.libs
|
||||
tests_functionaltests_functionaltests_LDADD = -lcmocka -lstabber -lexpect -ltcl8.6
|
||||
|
||||
man1_MANS = $(man1_sources)
|
||||
|
||||
1
external/stabber
vendored
Submodule
1
external/stabber
vendored
Submodule
Submodule external/stabber added at 3e5c220071
@@ -139,13 +139,17 @@ prof_start(void)
|
||||
int
|
||||
init_prof_test(void **state)
|
||||
{
|
||||
fprintf(stderr, "\n[TEST] init_prof_test() called\n");
|
||||
gboolean started = FALSE;
|
||||
for (int p = 5230; p < 5250; ++p) {
|
||||
fprintf(stderr, "[TEST] Trying to start stabber on port %d\n", p);
|
||||
if (stbbr_start(STBBR_LOGDEBUG, p, 0) == 0) {
|
||||
stub_port = p;
|
||||
fprintf(stderr, "[TEST] Stabber started successfully on port %d\n", p);
|
||||
started = TRUE;
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "[TEST] Port %d failed, trying next\n", p);
|
||||
}
|
||||
if (!started) {
|
||||
assert_true(FALSE); // could not start stabber on any port in range
|
||||
@@ -254,23 +258,66 @@ prof_connect_with_roster(const char *roster)
|
||||
// Set up stabber to expect password "password"
|
||||
stbbr_auth_passwd("password");
|
||||
|
||||
stbbr_for_id("prof_presence_1",
|
||||
"<presence id='prof_presence_1' lang='en' to='stabber@localhost/profanity' from='stabber@localhost/profanity'>"
|
||||
"<priority>0</priority>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io/' ver='f8mrtdyAmhnj8Ca+630bThSL718='/>"
|
||||
"</presence>"
|
||||
);
|
||||
|
||||
char connect_cmd[128];
|
||||
snprintf(connect_cmd, sizeof(connect_cmd), "/connect stabber@localhost server 127.0.0.1 port %d tls allow", stub_port);
|
||||
snprintf(connect_cmd, sizeof(connect_cmd), "/connect stabber@localhost server 127.0.0.1 port %d tls disable", stub_port);
|
||||
fprintf(stderr, "\n[TEST] Sending connect command: %s\n", connect_cmd);
|
||||
fprintf(stderr, "[TEST] stub_port = %d\n", stub_port);
|
||||
prof_input(connect_cmd);
|
||||
|
||||
// Check password prompt appears
|
||||
assert_true(prof_output_regex("password:"));
|
||||
|
||||
prof_input("password");
|
||||
|
||||
// Allow time for profanity to connect
|
||||
exp_timeout = 30;
|
||||
assert_true(prof_output_regex("stabber@localhost/profanity logged in successfully, .+online.+ \\(priority 0\\)\\."));
|
||||
exp_timeout = 60;
|
||||
|
||||
// First check: did we get any connection message?
|
||||
gboolean got_connecting = prof_output_regex("Connecting as stabber@localhost");
|
||||
gboolean got_success = FALSE;
|
||||
gboolean got_failure = FALSE;
|
||||
|
||||
if (got_connecting) {
|
||||
fprintf(stderr, "\nDEBUG: Saw 'Connecting as' message, waiting longer for result...\n");
|
||||
sleep(5); // Give extra time for SASL + bind
|
||||
|
||||
// Try to dump whatever is on the screen by sending Enter and reading response
|
||||
prof_input("");
|
||||
usleep(500000); // 0.5s
|
||||
|
||||
// Now wait for success or failure
|
||||
got_success = prof_output_regex("logged in successfully");
|
||||
if (!got_success) {
|
||||
got_failure = prof_output_regex("failed|Failed|error|Error|disconnect|Disconnect");
|
||||
if (!got_failure) {
|
||||
fprintf(stderr, "\nDEBUG: No success or failure after 5s, sending /who to trigger output...\n");
|
||||
// Send a command to see if connection is actually established
|
||||
prof_input("/who");
|
||||
usleep(500000);
|
||||
got_success = prof_output_regex("logged in successfully|online");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Maybe we went straight to success?
|
||||
got_success = prof_output_regex("logged in successfully");
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nDEBUG: got_connecting=%d got_success=%d got_failure=%d\n",
|
||||
got_connecting, got_success, got_failure);
|
||||
|
||||
if (got_success) {
|
||||
assert_true(prof_output_regex(".+online.+ \\(priority 0\\)\\."));
|
||||
} else {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
exp_timeout = 10;
|
||||
stbbr_wait_for("prof_presence_*");
|
||||
// Wait for presence stanza to be sent (content-based, not ID-based)
|
||||
assert_true(stbbr_received(
|
||||
"<presence id=\"*\">"
|
||||
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" node=\"http://profanity-im.github.io/\" ver=\"*\"/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user