Skip to content

Commit 4098b7c

Browse files
committed
Fix tests [18] --filter=[core]
1 parent 1cfba7e commit 4098b7c

File tree

6 files changed

+20
-26
lines changed

6 files changed

+20
-26
lines changed

core-tests/src/network/client.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,7 @@ TEST(client, bind) {
420420
ASSERT_EQ(cli.bind("192.0.0.1", 9999), SW_ERR);
421421
ASSERT_ERREQ(EADDRNOTAVAIL);
422422
ASSERT_EQ(cli.bind("127.0.0.1", 80), SW_ERR);
423-
if (swoole::test::is_github_ci()) {
424-
ASSERT_ERREQ(EINVAL);
425-
} else {
426-
ASSERT_ERREQ(EACCES);
427-
}
423+
ASSERT_ERREQ(EACCES);
428424
}
429425

430426
// DNS 报文头部结构

include/swoole_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class Client {
152152
return recv_(this, _data, _length, _flags);
153153
}
154154

155-
int bind(const std::string &addr, int port);
155+
int bind(const std::string &addr, int port) const;
156156
int sleep();
157157
int wakeup();
158158
int sendto(const std::string &host, int port, const char *data, size_t len) const;

run-core-tests.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ cd "${__DIR__}" || exit 1
1212

1313
tasks=$(./bin/core-tests --gtest_list_tests | awk '/\./') || exit 255
1414
for task in $tasks; do
15-
./bin/core-tests --gtest_filter="$task"*
15+
execute_command="./bin/core-tests"
16+
17+
if [ "$task" = "log." ]; then
18+
$execute_command --gtest_filter="$task"*
19+
else
20+
sudo -E "$execute_command" --gtest_filter="$task"*
21+
fi
22+
1623
if [ $? -ne 0 ]; then
1724
exit 255
1825
fi

src/coroutine/socket.cc

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#include "swoole_coroutine_socket.h"
2727
#include "swoole_coroutine_system.h"
2828

29-
namespace swoole {
30-
namespace coroutine {
29+
namespace swoole::coroutine {
3130
Socket::TimeoutType Socket::timeout_type_list[4] = {TIMEOUT_DNS, TIMEOUT_CONNECT, TIMEOUT_READ, TIMEOUT_WRITE};
3231

3332
void Socket::timer_callback(Timer *timer, TimerNode *tnode) {
@@ -423,19 +422,13 @@ double Socket::get_timeout(const TimeoutType type) const {
423422
String *Socket::get_read_buffer() {
424423
if (sw_unlikely(!read_buffer)) {
425424
read_buffer = make_string(SW_BUFFER_SIZE_BIG, buffer_allocator);
426-
if (!read_buffer) {
427-
throw std::bad_alloc();
428-
}
429425
}
430426
return read_buffer;
431427
}
432428

433429
String *Socket::get_write_buffer() {
434430
if (sw_unlikely(!write_buffer)) {
435431
write_buffer = make_string(SW_BUFFER_SIZE_BIG, buffer_allocator);
436-
if (!write_buffer) {
437-
throw std::bad_alloc();
438-
}
439432
}
440433
return write_buffer;
441434
}
@@ -643,17 +636,17 @@ bool Socket::connect(const std::string &_host, int _port, int flags) {
643636
break;
644637
}
645638

646-
if (connect(&server_addr.addr.ss, server_addr.len) == false) {
639+
if (!connect(&server_addr.addr.ss, server_addr.len)) {
647640
return false;
648641
}
649642

650643
// socks5 proxy
651-
if (socks5_proxy && socks5_handshake() == false) {
644+
if (socks5_proxy && !socks5_handshake()) {
652645
set_err(SW_ERROR_SOCKS5_HANDSHAKE_FAILED);
653646
return false;
654647
}
655648
// http proxy
656-
if (http_proxy && !http_proxy->dont_handshake && http_proxy_handshake() == false) {
649+
if (http_proxy && !http_proxy->dont_handshake && !http_proxy_handshake()) {
657650
set_err(SW_ERROR_HTTP_PROXY_HANDSHAKE_FAILED);
658651
return false;
659652
}
@@ -1711,6 +1704,4 @@ bool Socket::TimeoutController::has_timedout(const enum TimeoutType _type) {
17111704
}
17121705
return false;
17131706
}
1714-
1715-
} // namespace coroutine
1716-
} // namespace swoole
1707+
} // namespace swoole::coroutine

src/network/address.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ static bool IN_IS_ADDR_LOOPBACK(const in_addr *a) {
2222
return a->s_addr == htonl(INADDR_LOOPBACK);
2323
}
2424

25-
namespace swoole::network {
25+
namespace swoole {
26+
namespace network {
2627
static thread_local char tmp_address[INET6_ADDRSTRLEN];
2728

2829
const char *Address::addr_str(int family, const void *addr) {
@@ -178,5 +179,5 @@ bool Address::is_loopback_addr() const {
178179
}
179180
return false;
180181
}
181-
182-
} // namespace swoole::network
182+
} // namespace network
183+
} // namespace swoole

src/network/client.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
namespace swoole {
3030
namespace network {
31-
3231
static int Client_inet_addr(Client *cli, const char *host, int port);
3332
static int Client_tcp_connect_sync(Client *cli, const char *host, int port, double _timeout, int nonblock);
3433
static int Client_tcp_connect_async(Client *cli, const char *host, int port, double timeout, int nonblock);
@@ -107,7 +106,7 @@ Client::Client(SocketType _type, bool _async) : async(_async) {
107106
protocol.onPackage = Client_onPackage;
108107
}
109108

110-
int Client::bind(const std::string &addr, int port) {
109+
int Client::bind(const std::string &addr, int port) const {
111110
if (socket->set_reuse_addr() < 0) {
112111
swoole_sys_warning("setsockopt(%d, SO_REUSEADDR) failed", socket->get_fd());
113112
}

0 commit comments

Comments
 (0)