OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <sys/stat.h> | 5 #include <sys/stat.h> |
6 #include <sys/types.h> | 6 #include <sys/types.h> |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include <glib.h> | 11 #include <glib.h> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 gboolean StartAndCancelInRunLoop(gpointer data) { | 61 gboolean StartAndCancelInRunLoop(gpointer data) { |
62 CancelTestData* cancel_test_data = reinterpret_cast<CancelTestData*>(data); | 62 CancelTestData* cancel_test_data = reinterpret_cast<CancelTestData*>(data); |
63 vector<string> cmd; | 63 vector<string> cmd; |
64 cmd.push_back("./test_http_server"); | 64 cmd.push_back("./test_http_server"); |
65 uint32_t tag = Subprocess::Get().Exec(cmd, CallbackBad, NULL); | 65 uint32_t tag = Subprocess::Get().Exec(cmd, CallbackBad, NULL); |
66 EXPECT_NE(0, tag); | 66 EXPECT_NE(0, tag); |
67 cancel_test_data->spawned = true; | 67 cancel_test_data->spawned = true; |
68 printf("spawned\n"); | 68 printf("spawned\n"); |
69 // Wait for server to be up and running | 69 // Wait for server to be up and running |
| 70 useconds_t total_wait_time = 0; |
| 71 const useconds_t kMaxWaitTime = 3 * 1000000; // 3 seconds |
70 for (;;) { | 72 for (;;) { |
71 int status = | 73 int status = |
72 System(StringPrintf("wget -O /dev/null http://127.0.0.1:%d/foo", | 74 System(StringPrintf("wget -O /dev/null http://127.0.0.1:%d/foo", |
73 kLocalHttpPort)); | 75 kLocalHttpPort)); |
74 EXPECT_NE(-1, status) << "system() failed"; | 76 EXPECT_NE(-1, status) << "system() failed"; |
75 EXPECT_TRUE(WIFEXITED(status)) | 77 EXPECT_TRUE(WIFEXITED(status)) |
76 << "command failed to run or died abnormally"; | 78 << "command failed to run or died abnormally"; |
77 if (0 == WEXITSTATUS(status)) | 79 if (0 == WEXITSTATUS(status)) |
78 break; | 80 break; |
79 usleep(100 * 1000); // 100 ms | 81 |
| 82 const useconds_t kSleepTime = 100 * 1000; // 100ms |
| 83 usleep(kSleepTime); // 100 ms |
| 84 total_wait_time += kSleepTime; |
| 85 CHECK_LT(total_wait_time, kMaxWaitTime); |
80 } | 86 } |
81 Subprocess::Get().CancelExec(tag); | 87 Subprocess::Get().CancelExec(tag); |
82 return FALSE; | 88 return FALSE; |
83 } | 89 } |
84 } // namespace {} | 90 } // namespace {} |
85 | 91 |
86 gboolean ExitWhenDone(gpointer data) { | 92 gboolean ExitWhenDone(gpointer data) { |
87 CancelTestData* cancel_test_data = reinterpret_cast<CancelTestData*>(data); | 93 CancelTestData* cancel_test_data = reinterpret_cast<CancelTestData*>(data); |
88 if (cancel_test_data->spawned && !Subprocess::Get().SubprocessInFlight()) { | 94 if (cancel_test_data->spawned && !Subprocess::Get().SubprocessInFlight()) { |
89 // tear down the sub process | 95 // tear down the sub process |
(...skipping 16 matching lines...) Expand all Loading... |
106 cancel_test_data.spawned = false; | 112 cancel_test_data.spawned = false; |
107 cancel_test_data.loop = loop; | 113 cancel_test_data.loop = loop; |
108 g_timeout_add(100, &StartAndCancelInRunLoop, &cancel_test_data); | 114 g_timeout_add(100, &StartAndCancelInRunLoop, &cancel_test_data); |
109 g_timeout_add(10, &ExitWhenDone, &cancel_test_data); | 115 g_timeout_add(10, &ExitWhenDone, &cancel_test_data); |
110 g_main_loop_run(loop); | 116 g_main_loop_run(loop); |
111 g_main_loop_unref(loop); | 117 g_main_loop_unref(loop); |
112 printf("here\n"); | 118 printf("here\n"); |
113 } | 119 } |
114 | 120 |
115 } // namespace chromeos_update_engine | 121 } // namespace chromeos_update_engine |
OLD | NEW |