Skip to content

Commit ca38513

Browse files
committed
tests: Go to cleanup label by default on socket connect failure.
Most of the time, we should go to the cleanup label, rather than returning -1 immediately (which may lead to some cleanup getting skipped); add a second macro for the old behavior.
1 parent 07dbecb commit ca38513

5 files changed

Lines changed: 6 additions & 4 deletions

File tree

tests/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static int parse_options(int argc, char *argv[])
190190
option_debug++;
191191
break;
192192
case 'D':
193-
if (option_debug_bbs == MAX_DEBUG) {
193+
if (option_debug_bbs == MAX_DEBUG) {
194194
fprintf(stderr, "Maximum BBS debug level is %d\n", MAX_DEBUG);
195195
return -1;
196196
}

tests/test.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ int test_client_drain(int fd, int ms);
154154
/* We really may need up to 150ms when under valgrind */
155155
#define CLIENT_DRAIN(fd) test_client_drain(fd, 150)
156156

157-
#define REQUIRE_FD(fd) if (fd < 0) { bbs_error("File descriptor is not set\n"); return -1; }
157+
#define REQUIRE_FD(fd) if (fd < 0) { bbs_error("File descriptor is not set\n"); goto cleanup; }
158+
#define REQUIRE_FD_RETURN(fd) if (fd < 0) { bbs_error("File descriptor is not set\n"); return -1; }
158159

159160
#define DIRECTORY_EXPECT_FILE_COUNT(dir, cnt) { \
160161
int _dir_cnt = test_dir_file_count(dir); \

tests/test_imap_fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static int make_messages(void)
167167

168168
send_count = 0;
169169
clientfd = test_make_socket(25);
170-
REQUIRE_FD(clientfd);
170+
REQUIRE_FD_RETURN(clientfd);
171171

172172
res |= send_message(clientfd, "messages/multipart.eml");
173173
res |= send_message(clientfd, "messages/multipart2.eml");

tests/test_telnet.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ static int run(void)
132132

133133
res = 0;
134134

135+
cleanup:
135136
cleanup_fds(fds);
136137
return res;
137138
}

tests/test_webmail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int send_messages(void)
178178
int num_messages = 25;
179179

180180
clientfd = test_make_socket(25);
181-
REQUIRE_FD(clientfd);
181+
REQUIRE_FD_RETURN(clientfd);
182182

183183
while (num_messages--) {
184184
res |= send_message(clientfd);

0 commit comments

Comments
 (0)