aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/grappler/utils_test.cc
diff options
context:
space:
mode:
authorGravatar Vinu Rajashekhar <vinuraja@google.com>2017-03-15 23:24:41 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-03-16 00:49:09 -0700
commit1ce242420ecb64b196f29d510f51e795c92696ca (patch)
treeca46b71b5e52f90b39efcf7e60bc7a221e9552bc /tensorflow/core/grappler/utils_test.cc
parent91d502ad1f752838371c0f5059c1b2dce5f6e074 (diff)
- Makes SingleMachine::Run(...) thread-safe.
Change: 150289918
Diffstat (limited to 'tensorflow/core/grappler/utils_test.cc')
-rw-r--r--tensorflow/core/grappler/utils_test.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/tensorflow/core/grappler/utils_test.cc b/tensorflow/core/grappler/utils_test.cc
index f5d6877637..766cedd65d 100644
--- a/tensorflow/core/grappler/utils_test.cc
+++ b/tensorflow/core/grappler/utils_test.cc
@@ -14,6 +14,9 @@ limitations under the License.
==============================================================================*/
#include "tensorflow/core/grappler/utils.h"
+#include "tensorflow/core/lib/core/status.h"
+#include "tensorflow/core/lib/core/threadpool.h"
+#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/test.h"
namespace tensorflow {
@@ -60,6 +63,24 @@ TEST_F(UtilsTest, AddNodeNamePrefix) {
EXPECT_EQ("OPTIMIZED-", AddPrefixToNodeName("", "OPTIMIZED"));
}
+TEST_F(UtilsTest, ExecuteWithTimeout) {
+ std::unique_ptr<thread::ThreadPool> thread_pool(
+ new thread::ThreadPool(Env::Default(), "ExecuteWithTimeout", 2));
+ ASSERT_TRUE(ExecuteWithTimeout(
+ []() { // Do nothing.
+ },
+ 1 /* timeout_in_ms */, thread_pool.get()));
+ // This should time out.
+ ASSERT_FALSE(ExecuteWithTimeout([]() { sleep(1); }, 1 /* timeout_in_ms */,
+ thread_pool.get()));
+ // This should run till the end.
+ ASSERT_TRUE(ExecuteWithTimeout([]() { sleep(1); }, 0 /* timeout_in_ms */,
+ thread_pool.get()));
+
+ // Deleting before local variables go off the stack.
+ thread_pool.reset();
+}
+
} // namespace
} // namespace grappler
} // namespace tensorflow