Skip to content

Commit fc5feee

Browse files
committed
Added tests [12] --filter=[core] --verbose
1 parent b548ee5 commit fc5feee

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

core-tests/src/coroutine/hook.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,13 @@ TEST(coroutine_hook, timeout) {
409409
size_t length = text.length();
410410

411411
// unregister fd
412+
errno = 0;
412413
ASSERT_EQ(swoole_coroutine_socket_set_timeout(pairs[0], SO_SNDTIMEO, 0.05), -1);
414+
ASSERT_EQ(errno, EINVAL);
415+
416+
errno = 0;
417+
ASSERT_EQ(swoole_coroutine_socket_set_connect_timeout(pairs[0], 0.05), -1);
418+
ASSERT_EQ(errno, EINVAL);
413419

414420
swoole::Coroutine::create([&](void *) {
415421
ASSERT_EQ(swoole_coroutine_socket_create(pairs[0]), 0);
@@ -694,3 +700,31 @@ TEST(coroutine_hook, unwrap) {
694700
ASSERT_EQ(swoole_coroutine_socket_unwrap(_sock0->get_fd()), -1);
695701
});
696702
}
703+
704+
static void test_freopen() {
705+
auto output_file = "/tmp/output.txt";
706+
auto fp = swoole_coroutine_fopen(TEST_LOG_FILE, "w");
707+
ASSERT_NE(fp, nullptr);
708+
swoole_coroutine_fputs("hello\n", fp);
709+
710+
ASSERT_NE(swoole_coroutine_freopen(output_file, "w", fp), nullptr);
711+
swoole_coroutine_fputs("world\n", fp);
712+
713+
swoole_coroutine_fclose(fp);
714+
715+
auto rs1 = swoole::file_get_contents(output_file);
716+
ASSERT_FALSE(rs1->contains("hello\n"));
717+
ASSERT_TRUE(rs1->contains("world\n"));
718+
719+
auto rs2 = swoole::file_get_contents(TEST_LOG_FILE);
720+
ASSERT_TRUE(rs2->contains("hello\n"));
721+
ASSERT_FALSE(rs2->contains("world\n"));
722+
723+
unlink(TEST_LOG_FILE);
724+
unlink(output_file);
725+
}
726+
727+
TEST(coroutine_hook, freopen) {
728+
coroutine::run([&](void *arg) { test_freopen(); });
729+
test_freopen();
730+
}

src/protocol/ssl.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void swoole_ssl_init(void) {
5454
}
5555

5656
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG | OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS,
57-
nullptr);
57+
nullptr);
5858

5959
ssl_connection_index = SSL_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
6060
if (ssl_connection_index < 0) {
@@ -98,7 +98,6 @@ const char *swoole_ssl_get_error() {
9898
return sw_tg_buffer()->str;
9999
}
100100

101-
102101
static void swoole_ssl_info_callback(const SSL *ssl, int where, int ret) {
103102
BIO *rbio, *wbio;
104103
Socket *sock;

0 commit comments

Comments
 (0)