| 445 | }; |
| 446 | |
| 447 | void* FailedWriter(void* void_arg) { |
| 448 | WriterArg* arg = static_cast<WriterArg*>(void_arg); |
| 449 | brpc::SocketUniquePtr sock; |
| 450 | if (brpc::Socket::Address(arg->socket_id, &sock) < 0) { |
| 451 | printf("Fail to address SocketId=%" PRIu64 "\n", arg->socket_id); |
| 452 | return NULL; |
| 453 | } |
| 454 | char buf[32]; |
| 455 | for (size_t i = 0; i < arg->times; ++i) { |
| 456 | bthread_id_t id; |
| 457 | EXPECT_EQ(0, bthread_id_create(&id, NULL, NULL)); |
| 458 | snprintf(buf, sizeof(buf), "%0" BAIDU_SYMBOLSTR(NUMBER_WIDTH) "lu", |
| 459 | i + arg->offset); |
| 460 | butil::IOBuf src; |
| 461 | src.append(buf); |
| 462 | brpc::Socket::WriteOptions wopt; |
| 463 | wopt.id_wait = id; |
| 464 | sock->Write(&src, &wopt); |
| 465 | EXPECT_EQ(0, bthread_id_join(id)); |
| 466 | // Only the first connect can see ECONNREFUSED and then |
| 467 | // calls `SetFailed' making others' error_code=EINVAL |
| 468 | //EXPECT_EQ(ECONNREFUSED, error_code); |
| 469 | } |
| 470 | return NULL; |
| 471 | } |
| 472 | |
| 473 | TEST_F(SocketTest, fail_to_connect) { |
| 474 | const size_t REP = 10; |
nothing calls this directly
no test coverage detected