| Index: net/test/spawned_test_server/remote_test_server.cc
|
| diff --git a/net/test/spawned_test_server/remote_test_server.cc b/net/test/spawned_test_server/remote_test_server.cc
|
| index c563242bb3c66e9991178279c073eb5eb43e81da..1baab8ceab6bfa672c9f7648736edb74ac7de21a 100644
|
| --- a/net/test/spawned_test_server/remote_test_server.cc
|
| +++ b/net/test/spawned_test_server/remote_test_server.cc
|
| @@ -13,6 +13,7 @@
|
| #include "base/files/file_path.h"
|
| #include "base/files/file_util.h"
|
| #include "base/json/json_writer.h"
|
| +#include "base/lazy_instance.h"
|
| #include "base/logging.h"
|
| #include "base/path_service.h"
|
| #include "base/strings/string_number_conversions.h"
|
| @@ -27,6 +28,31 @@ namespace net {
|
|
|
| namespace {
|
|
|
| +// Based on how the Android runner sets things up, it is only valid for one
|
| +// RemoteTestServer to be active on the device at a time.
|
| +class RemoteTestServerTracker {
|
| + public:
|
| + void StartingServer() {
|
| + base::AutoLock l(lock_);
|
| + CHECK_EQ(count_, 0);
|
| + count_++;
|
| + }
|
| +
|
| + void StoppingServer() {
|
| + base::AutoLock l(lock_);
|
| + CHECK_EQ(count_, 1);
|
| + count_--;
|
| + }
|
| +
|
| + private:
|
| + // |lock_| protects access to |count_|.
|
| + base::Lock lock_;
|
| + int count_ = 0;
|
| +};
|
| +
|
| +base::LazyInstance<RemoteTestServerTracker>::Leaky tracker =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| // To reduce the running time of tests, tests may be sharded across several
|
| // devices. This means that it may be necessary to support multiple instances
|
| // of the test server spawner and the Python test server simultaneously on the
|
| @@ -92,6 +118,9 @@ RemoteTestServer::~RemoteTestServer() {
|
| bool RemoteTestServer::Start() {
|
| if (spawner_communicator_.get())
|
| return true;
|
| +
|
| + tracker.Get().StartingServer();
|
| +
|
| spawner_communicator_.reset(new SpawnerCommunicator(spawner_server_port_));
|
|
|
| base::DictionaryValue arguments_dict;
|
| @@ -148,8 +177,15 @@ bool RemoteTestServer::BlockUntilStarted() {
|
| bool RemoteTestServer::Stop() {
|
| if (!spawner_communicator_.get())
|
| return true;
|
| +
|
| + tracker.Get().StoppingServer();
|
| +
|
| CleanUpWhenStoppingServer();
|
| bool stopped = spawner_communicator_->StopServer();
|
| +
|
| + if (!stopped)
|
| + LOG(ERROR) << "Failed stopping RemoteTestServer";
|
| +
|
| // Explicitly reset |spawner_communicator_| to avoid reusing the stopped one.
|
| spawner_communicator_.reset(NULL);
|
| return stopped;
|
|
|