adb: improve socket tests.

Make it so that the socket tests don't leak until your machine blows up
by switching an infinite loop into an assertion failure.

Bug: http://b/74616284
Test: adb_test
Change-Id: If618c26b224b660548454f542cab79bebe46f80e
(cherry picked from commit ecb96ac04d7be37eae168658d50003434407b1ac)
diff --git a/adb/socket_test.cpp b/adb/socket_test.cpp
index c818fca..44d3276 100644
--- a/adb/socket_test.cpp
+++ b/adb/socket_test.cpp
@@ -113,16 +113,12 @@
     asocket* s = create_local_socket(arg->socket_fd);
     ASSERT_TRUE(s != nullptr);
     arg->bytes_written = 0;
-    while (true) {
-        std::string data;
-        data.resize(MAX_PAYLOAD);
-        arg->bytes_written += data.size();
-        int ret = s->enqueue(s, std::move(data));
-        if (ret == 1) {
-            // The writer has one packet waiting to send.
-            break;
-        }
-    }
+
+    std::string data;
+    data.resize(MAX_PAYLOAD);
+    arg->bytes_written += data.size();
+    int ret = s->enqueue(s, std::move(data));
+    ASSERT_EQ(1, ret);
 
     asocket* cause_close_s = create_local_socket(arg->cause_close_fd);
     ASSERT_TRUE(cause_close_s != nullptr);
@@ -233,15 +229,16 @@
     PrepareThread();
     std::thread thread(fdevent_loop);
 
-    ASSERT_TRUE(WriteFdExactly(head_fd[0], "foo", 3));
-    ASSERT_EQ(0, adb_shutdown(head_fd[0], SHUT_RD));
-    const char* str = "write succeeds, but local_socket will fail to write";
-    ASSERT_TRUE(WriteFdExactly(tail_fd[0], str, strlen(str)));
-    ASSERT_TRUE(WriteFdExactly(head_fd[0], "bar", 3));
-    char buf[6];
-    ASSERT_TRUE(ReadFdExactly(tail_fd[0], buf, 6));
+    EXPECT_TRUE(WriteFdExactly(head_fd[0], "foo", 3));
 
-    ASSERT_EQ(0, memcmp(buf, "foobar", 6));
+    EXPECT_EQ(0, adb_shutdown(head_fd[0], SHUT_RD));
+    const char* str = "write succeeds, but local_socket will fail to write";
+    EXPECT_TRUE(WriteFdExactly(tail_fd[0], str, strlen(str)));
+    EXPECT_TRUE(WriteFdExactly(head_fd[0], "bar", 3));
+
+    char buf[6];
+    EXPECT_TRUE(ReadFdExactly(tail_fd[0], buf, 6));
+    EXPECT_EQ(0, memcmp(buf, "foobar", 6));
 
     adb_close(head_fd[0]);
     adb_close(tail_fd[0]);