Apache Mesos
gtest.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License
12 
13 #ifndef __PROCESS_GTEST_HPP__
14 #define __PROCESS_GTEST_HPP__
15 
16 #include <gtest/gtest.h>
17 
18 #include <string>
19 
20 #include <process/check.hpp>
21 #include <process/clock.hpp>
22 #include <process/future.hpp>
24 #include <process/http.hpp>
25 
26 #include <stout/duration.hpp>
27 #include <stout/gtest.hpp>
28 #include <stout/option.hpp>
29 #include <stout/os.hpp>
30 #include <stout/stopwatch.hpp>
31 #include <stout/strings.hpp>
32 
33 namespace process {
34 
35 constexpr char READONLY_HTTP_AUTHENTICATION_REALM[] = "libprocess-readonly";
36 constexpr char READWRITE_HTTP_AUTHENTICATION_REALM[] = "libprocess-readwrite";
37 
38 // A simple test event listener that makes sure to resume the clock
39 // after each test even if the previous test had a partial result
40 // (i.e., an ASSERT_* failed).
41 class ClockTestEventListener : public ::testing::EmptyTestEventListener
42 {
43 public:
44  // Returns the singleton instance of the listener.
46  {
47  static ClockTestEventListener* listener = new ClockTestEventListener();
48  return listener;
49  }
50 
51  void OnTestEnd(const ::testing::TestInfo&) override
52  {
53  if (process::Clock::paused()) {
55  }
56  }
57 private:
59 };
60 
61 
62 namespace internal {
63 
64 // Returns true if the future becomes ready, discarded, or failed
65 // after the wait.
66 template <typename T>
67 bool await(const process::Future<T>& future, const Duration& duration)
68 {
69  if (!process::Clock::paused()) {
70  return future.await(duration);
71  }
72 
73  // If the clock is paused, no new timers will expire.
74  // Future::await(duration) may hang forever because it depends on
75  // a timer to expire after 'duration'. We instead ensure all
76  // expired timers are flushed and check if the future is satisfied.
77  Stopwatch stopwatch;
78  stopwatch.start();
79 
80  // Settle to make sure all expired timers are executed (not
81  // necessarily finished, see below).
83 
84  while (future.isPending() && stopwatch.elapsed() < duration) {
85  // Synchronous operations and asynchronous process::Process
86  // operations should finish when the above 'settle()' returns.
87  // Other types of async operations such as io::write() may not.
88  // Therefore we wait the specified duration for it to complete.
89  // Note that nothing prevents the operations to schedule more
90  // timeouts for some time in the future. These timeouts will
91  // never be executed due to the paused process::Clock. In this
92  // case we return after the stopwatch (system clock) runs out.
94  }
95 
96  return !future.isPending();
97 }
98 
99 } // namespace internal {
100 } // namespace process {
101 
102 
103 template <typename T>
104 ::testing::AssertionResult Await(
105  const char* expr,
106  const char*, // Unused string representation of 'duration'.
107  const process::Future<T>& actual,
108  const Duration& duration)
109 {
110  if (!process::internal::await(actual, duration)) {
111  return ::testing::AssertionFailure()
112  << "Failed to wait " << duration << " for " << expr;
113  }
114 
115  return ::testing::AssertionSuccess();
116 }
117 
118 
119 template <typename T>
120 ::testing::AssertionResult AwaitAssertReady(
121  const char* expr,
122  const char*, // Unused string representation of 'duration'.
123  const process::Future<T>& actual,
124  const Duration& duration)
125 {
126  if (!process::internal::await(actual, duration)) {
127  return ::testing::AssertionFailure()
128  << "Failed to wait " << duration << " for " << expr;
129  } else if (actual.isDiscarded()) {
130  return ::testing::AssertionFailure()
131  << expr << " was discarded";
132  } else if (actual.isFailed()) {
133  return ::testing::AssertionFailure()
134  << "(" << expr << ").failure(): " << actual.failure();
135  }
136 
137  return ::testing::AssertionSuccess();
138 }
139 
140 
141 template <typename T>
142 ::testing::AssertionResult AwaitAssertFailed(
143  const char* expr,
144  const char*, // Unused string representation of 'duration'.
145  const process::Future<T>& actual,
146  const Duration& duration)
147 {
148  if (!process::internal::await(actual, duration)) {
149  return ::testing::AssertionFailure()
150  << "Failed to wait " << duration << " for " << expr;
151  } else if (actual.isDiscarded()) {
152  return ::testing::AssertionFailure()
153  << expr << " was discarded";
154  } else if (actual.isReady()) {
155  return ::testing::AssertionFailure()
156  << expr << " is ready (" << ::testing::PrintToString(actual.get()) << ")";
157  }
158 
159  return ::testing::AssertionSuccess();
160 }
161 
162 
163 template <typename T>
164 ::testing::AssertionResult AwaitAssertDiscarded(
165  const char* expr,
166  const char*, // Unused string representation of 'duration'.
167  const process::Future<T>& actual,
168  const Duration& duration)
169 {
170  if (!process::internal::await(actual, duration)) {
171  return ::testing::AssertionFailure()
172  << "Failed to wait " << duration << " for " << expr;
173  } else if (actual.isFailed()) {
174  return ::testing::AssertionFailure()
175  << "(" << expr << ").failure(): " << actual.failure();
176  } else if (actual.isReady()) {
177  return ::testing::AssertionFailure()
178  << expr << " is ready (" << ::testing::PrintToString(actual.get()) << ")";
179  }
180 
181  return ::testing::AssertionSuccess();
182 }
183 
184 
185 template <typename T>
186 ::testing::AssertionResult AwaitAssertAbandoned(
187  const char* expr,
188  const char*, // Unused string representation of 'duration'.
189  const process::Future<T>& actual,
190  const Duration& duration)
191 {
193 
194  actual.onAny([=]() { latch->trigger(); });
195  actual.onAbandoned([=]() { latch->trigger(); });
196 
197  if (!latch->await(duration)) {
198  return ::testing::AssertionFailure()
199  << "Failed to wait " << duration << " for " << expr;
200  } else if (actual.isDiscarded()) {
201  return ::testing::AssertionFailure()
202  << expr << " was discarded";
203  } else if (actual.isReady()) {
204  return ::testing::AssertionFailure()
205  << expr << " is ready (" << ::testing::PrintToString(actual.get()) << ")";
206  } else if (actual.isFailed()) {
207  return ::testing::AssertionFailure()
208  << "(" << expr << ").failure(): " << actual.failure();
209  }
210 
211  CHECK_ABANDONED(actual);
212 
213  return ::testing::AssertionSuccess();
214 }
215 
216 
217 template <typename T1, typename T2>
218 ::testing::AssertionResult AwaitAssertEq(
219  const char* expectedExpr,
220  const char* actualExpr,
221  const char* durationExpr,
222  const T1& expected,
223  const process::Future<T2>& actual,
224  const Duration& duration)
225 {
226  const ::testing::AssertionResult result =
227  AwaitAssertReady(actualExpr, durationExpr, actual, duration);
228 
229  if (result) {
230  if (expected == actual.get()) {
231  return ::testing::AssertionSuccess();
232  } else {
233  return ::testing::AssertionFailure()
234  << "Value of: (" << actualExpr << ").get()\n"
235  << " Actual: " << ::testing::PrintToString(actual.get()) << "\n"
236  << "Expected: " << expectedExpr << "\n"
237  << "Which is: " << ::testing::PrintToString(expected);
238  }
239  }
240 
241  return result;
242 }
243 
244 
245 #define AWAIT_ASSERT_ABANDONED_FOR(actual, duration) \
246  ASSERT_PRED_FORMAT2(AwaitAssertAbandoned, actual, duration)
247 
248 
249 #define AWAIT_ASSERT_ABANDONED(actual) \
250  AWAIT_ASSERT_ABANDONED_FOR(actual, process::TEST_AWAIT_TIMEOUT)
251 
252 
253 #define AWAIT_EXPECT_ABANDONED_FOR(actual, duration) \
254  EXPECT_PRED_FORMAT2(AwaitAssertAbandoned, actual, duration)
255 
256 
257 #define AWAIT_EXPECT_ABANDONED(actual) \
258  AWAIT_EXPECT_ABANDONED_FOR(actual, process::TEST_AWAIT_TIMEOUT)
259 
260 
261 // TODO(bmahler): Differentiate EXPECT and ASSERT here.
262 #define AWAIT_FOR(actual, duration) \
263  ASSERT_PRED_FORMAT2(Await, actual, duration)
264 
265 
266 #define AWAIT(actual) \
267  AWAIT_FOR(actual, process::TEST_AWAIT_TIMEOUT)
268 
269 
270 #define AWAIT_ASSERT_READY_FOR(actual, duration) \
271  ASSERT_PRED_FORMAT2(AwaitAssertReady, actual, duration)
272 
273 
274 #define AWAIT_ASSERT_READY(actual) \
275  AWAIT_ASSERT_READY_FOR(actual, process::TEST_AWAIT_TIMEOUT)
276 
277 
278 #define AWAIT_READY_FOR(actual, duration) \
279  AWAIT_ASSERT_READY_FOR(actual, duration)
280 
281 
282 #define AWAIT_READY(actual) \
283  AWAIT_ASSERT_READY(actual)
284 
285 
286 #define AWAIT_EXPECT_READY_FOR(actual, duration) \
287  EXPECT_PRED_FORMAT2(AwaitAssertReady, actual, duration)
288 
289 
290 #define AWAIT_EXPECT_READY(actual) \
291  AWAIT_EXPECT_READY_FOR(actual, process::TEST_AWAIT_TIMEOUT)
292 
293 
294 #define AWAIT_ASSERT_FAILED_FOR(actual, duration) \
295  ASSERT_PRED_FORMAT2(AwaitAssertFailed, actual, duration)
296 
297 
298 #define AWAIT_ASSERT_FAILED(actual) \
299  AWAIT_ASSERT_FAILED_FOR(actual, process::TEST_AWAIT_TIMEOUT)
300 
301 
302 #define AWAIT_FAILED_FOR(actual, duration) \
303  AWAIT_ASSERT_FAILED_FOR(actual, duration)
304 
305 
306 #define AWAIT_FAILED(actual) \
307  AWAIT_ASSERT_FAILED(actual)
308 
309 
310 #define AWAIT_EXPECT_FAILED_FOR(actual, duration) \
311  EXPECT_PRED_FORMAT2(AwaitAssertFailed, actual, duration)
312 
313 
314 #define AWAIT_EXPECT_FAILED(actual) \
315  AWAIT_EXPECT_FAILED_FOR(actual, process::TEST_AWAIT_TIMEOUT)
316 
317 
318 #define AWAIT_ASSERT_DISCARDED_FOR(actual, duration) \
319  ASSERT_PRED_FORMAT2(AwaitAssertDiscarded, actual, duration)
320 
321 
322 #define AWAIT_ASSERT_DISCARDED(actual) \
323  AWAIT_ASSERT_DISCARDED_FOR(actual, process::TEST_AWAIT_TIMEOUT)
324 
325 
326 #define AWAIT_DISCARDED_FOR(actual, duration) \
327  AWAIT_ASSERT_DISCARDED_FOR(actual, duration)
328 
329 
330 #define AWAIT_DISCARDED(actual) \
331  AWAIT_ASSERT_DISCARDED(actual)
332 
333 
334 #define AWAIT_EXPECT_DISCARDED_FOR(actual, duration) \
335  EXPECT_PRED_FORMAT2(AwaitAssertDiscarded, actual, duration)
336 
337 
338 #define AWAIT_EXPECT_DISCARDED(actual) \
339  AWAIT_EXPECT_DISCARDED_FOR(actual, process::TEST_AWAIT_TIMEOUT)
340 
341 
342 #define AWAIT_ASSERT_EQ_FOR(expected, actual, duration) \
343  ASSERT_PRED_FORMAT3(AwaitAssertEq, expected, actual, duration)
344 
345 
346 #define AWAIT_ASSERT_EQ(expected, actual) \
347  AWAIT_ASSERT_EQ_FOR(expected, actual, process::TEST_AWAIT_TIMEOUT)
348 
349 
350 #define AWAIT_EQ_FOR(expected, actual, duration) \
351  AWAIT_ASSERT_EQ_FOR(expected, actual, duration)
352 
353 
354 #define AWAIT_EQ(expected, actual) \
355  AWAIT_ASSERT_EQ(expected, actual)
356 
357 
358 #define AWAIT_EXPECT_EQ_FOR(expected, actual, duration) \
359  EXPECT_PRED_FORMAT3(AwaitAssertEq, expected, actual, duration)
360 
361 
362 #define AWAIT_EXPECT_EQ(expected, actual) \
363  AWAIT_EXPECT_EQ_FOR(expected, actual, process::TEST_AWAIT_TIMEOUT)
364 
365 
366 #define AWAIT_ASSERT_TRUE_FOR(actual, duration) \
367  AWAIT_ASSERT_EQ_FOR(true, actual, duration)
368 
369 
370 #define AWAIT_ASSERT_TRUE(actual) \
371  AWAIT_ASSERT_EQ(true, actual)
372 
373 
374 #define AWAIT_TRUE_FOR(actual, duration) \
375  AWAIT_ASSERT_TRUE_FOR(actual, duration)
376 
377 
378 #define AWAIT_TRUE(actual) \
379  AWAIT_ASSERT_TRUE(actual)
380 
381 
382 #define AWAIT_EXPECT_TRUE_FOR(actual, duration) \
383  AWAIT_EXPECT_EQ_FOR(true, actual, duration)
384 
385 
386 #define AWAIT_EXPECT_TRUE(actual) \
387  AWAIT_EXPECT_EQ(true, actual)
388 
389 
390 #define AWAIT_ASSERT_FALSE_FOR(actual, duration) \
391  AWAIT_ASSERT_EQ_FOR(false, actual, duration)
392 
393 
394 #define AWAIT_ASSERT_FALSE(actual) \
395  AWAIT_ASSERT_EQ(false, actual)
396 
397 
398 #define AWAIT_FALSE_FOR(actual, duration) \
399  AWAIT_ASSERT_FALSE_FOR(actual, duration)
400 
401 
402 #define AWAIT_FALSE(actual) \
403  AWAIT_ASSERT_FALSE(actual)
404 
405 
406 #define AWAIT_EXPECT_FALSE_FOR(actual, duration) \
407  AWAIT_EXPECT_EQ_FOR(false, actual, duration)
408 
409 
410 #define AWAIT_EXPECT_FALSE(actual) \
411  AWAIT_EXPECT_EQ(false, actual)
412 
413 
414 inline ::testing::AssertionResult AwaitAssertResponseStatusEq(
415  const char* expectedExpr,
416  const char* actualExpr,
417  const char* durationExpr,
418  const std::string& expected,
420  const Duration& duration)
421 {
422  const ::testing::AssertionResult result =
423  AwaitAssertReady(actualExpr, durationExpr, actual, duration);
424 
425  if (result) {
426  if (expected == actual->status) {
427  return ::testing::AssertionSuccess();
428  } else {
429  return ::testing::AssertionFailure()
430  << "Value of: (" << actualExpr << ")->status\n"
431  << " Actual: " << ::testing::PrintToString(actual->status) << "\n"
432  << "Expected: " << expectedExpr << "\n"
433  << "Which is: " << ::testing::PrintToString(expected) << "\n"
434  << " Body: " << ::testing::PrintToString(actual->body);
435  }
436  }
437 
438  return result;
439 }
440 
441 
442 #define AWAIT_ASSERT_RESPONSE_STATUS_EQ_FOR(expected, actual, duration) \
443  ASSERT_PRED_FORMAT3(AwaitAssertResponseStatusEq, expected, actual, duration)
444 
445 
446 #define AWAIT_ASSERT_RESPONSE_STATUS_EQ(expected, actual) \
447  AWAIT_ASSERT_RESPONSE_STATUS_EQ_FOR( \
448  expected, \
449  actual, \
450  process::TEST_AWAIT_TIMEOUT)
451 
452 
453 #define AWAIT_EXPECT_RESPONSE_STATUS_EQ_FOR(expected, actual, duration) \
454  EXPECT_PRED_FORMAT3(AwaitAssertResponseStatusEq, expected, actual, duration)
455 
456 
457 #define AWAIT_EXPECT_RESPONSE_STATUS_EQ(expected, actual) \
458  AWAIT_EXPECT_RESPONSE_STATUS_EQ_FOR( \
459  expected, \
460  actual, \
461  process::TEST_AWAIT_TIMEOUT)
462 
463 
464 inline ::testing::AssertionResult AwaitAssertResponseBodyEq(
465  const char* expectedExpr,
466  const char* actualExpr,
467  const char* durationExpr,
468  const std::string& expected,
470  const Duration& duration)
471 {
472  const ::testing::AssertionResult result =
473  AwaitAssertReady(actualExpr, durationExpr, actual, duration);
474 
475  if (result) {
476  if (expected == actual->body) {
477  return ::testing::AssertionSuccess();
478  } else {
479  return ::testing::AssertionFailure()
480  << "Value of: (" << actualExpr << ")->body\n"
481  << " Actual: " << ::testing::PrintToString(actual->body) << "\n"
482  << "Expected: " << expectedExpr << "\n"
483  << "Which is: " << ::testing::PrintToString(expected);
484  }
485  }
486 
487  return result;
488 }
489 
490 
491 #define AWAIT_ASSERT_RESPONSE_BODY_EQ_FOR(expected, actual, duration) \
492  ASSERT_PRED_FORMAT3(AwaitAssertResponseBodyEq, expected, actual, duration)
493 
494 
495 #define AWAIT_ASSERT_RESPONSE_BODY_EQ(expected, actual) \
496  AWAIT_ASSERT_RESPONSE_BODY_EQ_FOR( \
497  expected, \
498  actual, \
499  process::TEST_AWAIT_TIMEOUT)
500 
501 
502 #define AWAIT_EXPECT_RESPONSE_BODY_EQ_FOR(expected, actual, duration) \
503  EXPECT_PRED_FORMAT3(AwaitAssertResponseBodyEq, expected, actual, duration)
504 
505 
506 #define AWAIT_EXPECT_RESPONSE_BODY_EQ(expected, actual) \
507  AWAIT_EXPECT_RESPONSE_BODY_EQ_FOR( \
508  expected, \
509  actual, \
510  process::TEST_AWAIT_TIMEOUT)
511 
512 
513 inline ::testing::AssertionResult AwaitAssertResponseHeaderEq(
514  const char* expectedExpr,
515  const char* keyExpr,
516  const char* actualExpr,
517  const char* durationExpr,
518  const std::string& expected,
519  const std::string& key,
521  const Duration& duration)
522 {
523  const ::testing::AssertionResult result =
524  AwaitAssertReady(actualExpr, durationExpr, actual, duration);
525 
526  if (result) {
527  const Option<std::string> value = actual->headers.get(key);
528  if (value.isNone()) {
529  return ::testing::AssertionFailure()
530  << "Response does not contain header '" << key << "'";
531  } else if (expected == value.get()) {
532  return ::testing::AssertionSuccess();
533  } else {
534  return ::testing::AssertionFailure()
535  << "Value of: (" << actualExpr << ")->headers[" << keyExpr << "]\n"
536  << " Actual: " << ::testing::PrintToString(value.get()) << "\n"
537  << "Expected: " << expectedExpr << "\n"
538  << "Which is: " << ::testing::PrintToString(expected);
539  }
540  }
541 
542  return result;
543 }
544 
545 
546 #define AWAIT_ASSERT_RESPONSE_HEADER_EQ_FOR(expected, key, actual, duration) \
547  ASSERT_PRED_FORMAT4( \
548  AwaitAssertResponseHeaderEq, \
549  expected, \
550  key, \
551  actual, \
552  duration)
553 
554 
555 #define AWAIT_ASSERT_RESPONSE_HEADER_EQ(expected, key, actual) \
556  AWAIT_ASSERT_RESPONSE_HEADER_EQ_FOR( \
557  expected, \
558  key, \
559  actual, \
560  process::TEST_AWAIT_TIMEOUT)
561 
562 
563 #define AWAIT_EXPECT_RESPONSE_HEADER_EQ_FOR(expected, key, actual, duration) \
564  EXPECT_PRED_FORMAT4( \
565  AwaitAssertResponseHeaderEq, \
566  expected, \
567  key, \
568  actual, \
569  duration)
570 
571 
572 #define AWAIT_EXPECT_RESPONSE_HEADER_EQ(expected, key, actual) \
573  AWAIT_EXPECT_RESPONSE_HEADER_EQ_FOR( \
574  expected, \
575  key, \
576  actual, \
577  process::TEST_AWAIT_TIMEOUT)
578 
579 
580 inline ::testing::AssertionResult AwaitAssertExited(
581  const char* actualExpr,
582  const char* durationExpr,
583  const process::Future<Option<int>>& actual,
584  const Duration& duration)
585 {
586  const ::testing::AssertionResult result =
587  AwaitAssertReady(actualExpr, durationExpr, actual, duration);
588 
589  if (result) {
590  CHECK_READY(actual);
591  if (actual->isNone()) {
592  return ::testing::AssertionFailure()
593  << "(" << actualExpr << ").get() is NONE";
594  }
595 
596  return AssertExited(
597  strings::join("(", actualExpr, ")->get()").c_str(),
598  actual->get());
599  }
600 
601  return result;
602 }
603 
604 
605 #define AWAIT_ASSERT_EXITED_FOR(expected, actual, duration) \
606  ASSERT_PRED_FORMAT3(AwaitAssertExited, expected, actual, duration)
607 
608 
609 #define AWAIT_ASSERT_EXITED(expected, actual) \
610  AWAIT_ASSERT_EXITED_FOR(expected, actual, process::TEST_AWAIT_TIMEOUT)
611 
612 
613 #define AWAIT_EXPECT_EXITED_FOR(expected, actual, duration) \
614  EXPECT_PRED_FORMAT3(AwaitAssertExited, expected, actual, duration)
615 
616 
617 #define AWAIT_EXPECT_EXITED(expected, actual) \
618  AWAIT_EXPECT_EXITED_FOR(expected, actual, process::TEST_AWAIT_TIMEOUT)
619 
620 
621 inline ::testing::AssertionResult AwaitAssertExitStatusEq(
622  const char* expectedExpr,
623  const char* actualExpr,
624  const char* durationExpr,
625  const int expected,
626  const process::Future<Option<int>>& actual,
627  const Duration& duration)
628 {
629  const ::testing::AssertionResult result =
630  AwaitAssertExited(actualExpr, durationExpr, actual, duration);
631 
632  if (result) {
633  CHECK_READY(actual);
634  CHECK_SOME(actual.get());
635  return AssertExitStatusEq(
636  expectedExpr,
637  strings::join("(", actualExpr, ")->get()").c_str(),
638  expected,
639  actual->get());
640  }
641 
642  return result;
643 }
644 
645 
646 #define AWAIT_ASSERT_WEXITSTATUS_EQ_FOR(expected, actual, duration) \
647  ASSERT_PRED_FORMAT3(AwaitAssertExitStatusEq, expected, actual, duration)
648 
649 
650 #define AWAIT_ASSERT_WEXITSTATUS_EQ(expected, actual) \
651  AWAIT_ASSERT_WEXITSTATUS_EQ_FOR( \
652  expected, \
653  actual, \
654  process::TEST_AWAIT_TIMEOUT)
655 
656 
657 #define AWAIT_EXPECT_WEXITSTATUS_EQ_FOR(expected, actual, duration) \
658  EXPECT_PRED_FORMAT3(AwaitAssertExitStatusEq, expected, actual, duration)
659 
660 
661 #define AWAIT_EXPECT_WEXITSTATUS_EQ(expected, actual) \
662  AWAIT_EXPECT_WEXITSTATUS_EQ_FOR( \
663  expected, \
664  actual, \
665  process::TEST_AWAIT_TIMEOUT)
666 
667 
668 inline ::testing::AssertionResult AwaitAssertExitStatusNe(
669  const char* expectedExpr,
670  const char* actualExpr,
671  const char* durationExpr,
672  const int expected,
673  const process::Future<Option<int>>& actual,
674  const Duration& duration)
675 {
676  const ::testing::AssertionResult result =
677  AwaitAssertExited(actualExpr, durationExpr, actual, duration);
678 
679  if (result) {
680  CHECK_READY(actual);
681  CHECK_SOME(actual.get());
682  return AssertExitStatusNe(
683  expectedExpr,
684  strings::join("(", actualExpr, ")->get()").c_str(),
685  expected,
686  actual->get());
687  }
688 
689  return result;
690 }
691 
692 
693 #define AWAIT_ASSERT_WEXITSTATUS_NE_FOR(expected, actual, duration) \
694  ASSERT_PRED_FORMAT3(AwaitAssertExitStatusNe, expected, actual, duration)
695 
696 
697 #define AWAIT_ASSERT_WEXITSTATUS_NE(expected, actual) \
698  AWAIT_ASSERT_EXITSTATUS_NE_FOR( \
699  expected, \
700  actual, \
701  process::TEST_AWAIT_TIMEOUT)
702 
703 
704 #define AWAIT_EXPECT_WEXITSTATUS_NE_FOR(expected, actual, duration) \
705  EXPECT_PRED_FORMAT3(AwaitAssertExitStatusNe, expected, actual, duration)
706 
707 
708 #define AWAIT_EXPECT_WEXITSTATUS_NE(expected, actual) \
709  AWAIT_EXPECT_WEXITSTATUS_NE_FOR( \
710  expected, \
711  actual, \
712  process::TEST_AWAIT_TIMEOUT)
713 
714 
715 // Signals are't used on Windows, so #ifdef these out.
716 #ifndef __WINDOWS__
717 inline ::testing::AssertionResult AwaitAssertSignaled(
718  const char* actualExpr,
719  const char* durationExpr,
720  const process::Future<Option<int>>& actual,
721  const Duration& duration)
722 {
723  const ::testing::AssertionResult result =
724  AwaitAssertReady(actualExpr, durationExpr, actual, duration);
725 
726  if (result) {
727  CHECK_READY(actual);
728  if (actual->isNone()) {
729  return ::testing::AssertionFailure()
730  << "(" << actualExpr << ")->isNone() is true";
731  }
732 
733  return AssertSignaled(
734  strings::join("(", actualExpr, ")->get()").c_str(),
735  actual->get());
736  }
737 
738  return result;
739 }
740 
741 
742 #define AWAIT_ASSERT_SIGNALED_FOR(expected, actual, duration) \
743  ASSERT_PRED_FORMAT3(AwaitAssertSignaled, expected, actual, duration)
744 
745 
746 #define AWAIT_ASSERT_SIGNALED(expected, actual) \
747  AWAIT_ASSERT_SIGNALED_FOR(expected, actual, process::TEST_AWAIT_TIMEOUT)
748 
749 
750 #define AWAIT_EXPECT_SIGNALED_FOR(expected, actual, duration) \
751  EXPECT_PRED_FORMAT3(AwaitAssertSignaled, expected, actual, duration)
752 
753 
754 #define AWAIT_EXPECT_SIGNALED(expected, actual) \
755  AWAIT_EXPECT_SIGNALED_FOR(expected, actual, process::TEST_AWAIT_TIMEOUT)
756 
757 
758 inline ::testing::AssertionResult AwaitAssertTermSigEq(
759  const char* expectedExpr,
760  const char* actualExpr,
761  const char* durationExpr,
762  const int expected,
763  const process::Future<Option<int>>& actual,
764  const Duration& duration)
765 {
766  const ::testing::AssertionResult result =
767  AwaitAssertSignaled(actualExpr, durationExpr, actual, duration);
768 
769  if (result) {
770  CHECK_READY(actual);
771  CHECK_SOME(actual.get());
772  return AssertTermSigEq(
773  expectedExpr,
774  strings::join("(", actualExpr, ")->get()").c_str(),
775  expected,
776  actual->get());
777  }
778 
779  return result;
780 }
781 
782 
783 #define AWAIT_ASSERT_WTERMSIG_EQ_FOR(expected, actual, duration) \
784  ASSERT_PRED_FORMAT3(AwaitAssertTermSigEq, expected, actual, duration)
785 
786 
787 #define AWAIT_ASSERT_WTERMSIG_EQ(expected, actual) \
788  AWAIT_ASSERT_WTERMSIG_EQ_FOR( \
789  expected, \
790  actual, \
791  process::TEST_AWAIT_TIMEOUT)
792 
793 
794 #define AWAIT_EXPECT_WTERMSIG_EQ_FOR(expected, actual, duration) \
795  EXPECT_PRED_FORMAT3(AwaitAssertTermSigEq, expected, actual, duration)
796 
797 
798 #define AWAIT_EXPECT_WTERMSIG_EQ(expected, actual) \
799  AWAIT_EXPECT_WTERMSIG_EQ_FOR( \
800  expected, \
801  actual, \
802  process::TEST_AWAIT_TIMEOUT)
803 
804 
805 inline ::testing::AssertionResult AwaitAssertTermSigNe(
806  const char* expectedExpr,
807  const char* actualExpr,
808  const char* durationExpr,
809  const int expected,
810  const process::Future<Option<int>>& actual,
811  const Duration& duration)
812 {
813  const ::testing::AssertionResult result =
814  AwaitAssertSignaled(actualExpr, durationExpr, actual, duration);
815 
816  if (result) {
817  CHECK_READY(actual);
818  CHECK_SOME(actual.get());
819  return AssertTermSigNe(
820  expectedExpr,
821  strings::join("(", actualExpr, ")->get()").c_str(),
822  expected,
823  actual->get());
824  }
825 
826  return result;
827 }
828 
829 
830 #define AWAIT_ASSERT_WTERMSIG_NE_FOR(expected, actual, duration) \
831  ASSERT_PRED_FORMAT3(AwaitAssertTermSigNe, expected, actual, duration)
832 
833 
834 #define AWAIT_ASSERT_WTERMSIG_NE(expected, actual) \
835  AWAIT_ASSERT_TERMSIG_NE_FOR( \
836  expected, \
837  actual, \
838  process::TEST_AWAIT_TIMEOUT
839 
840 
841 #define AWAIT_EXPECT_TERMSIG_NE_FOR(expected, actual, duration) \
842  EXPECT_PRED_FORMAT3(AwaitAssertTermSigNe, expected, actual, duration)
843 
844 
845 #define AWAIT_EXPECT_WTERMSIG_NE(expected, actual) \
846  AWAIT_EXPECT_WTERMSIG_NE_FOR( \
847  expected, \
848  actual, \
849  process::TEST_AWAIT_TIMEOUT)
850 
851 
852 // TODO(benh):
853 // inline ::testing::AssertionResult AwaitAssertStopped(...)
854 // inline ::testing::AssertionResult AwaitAssertStopSigEq(...)
855 // inline ::testing::AssertionResult AwaitAssertStopSigNe(...)
856 #endif // __WINDOWS__
857 
858 #endif // __PROCESS_GTEST_HPP__
bool isReady() const
Definition: future.hpp:1215
inline::testing::AssertionResult AssertExitStatusNe(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:317
::testing::AssertionResult AwaitAssertDiscarded(const char *expr, const char *, const process::Future< T > &actual, const Duration &duration)
Definition: gtest.hpp:164
::testing::AssertionResult AwaitAssertAbandoned(const char *expr, const char *, const process::Future< T > &actual, const Duration &duration)
Definition: gtest.hpp:186
void OnTestEnd(const ::testing::TestInfo &) override
Definition: gtest.hpp:51
const T & get() const
Definition: future.hpp:1294
std::stringstream & join(std::stringstream &stream, const std::string &separator, T &&...args)
Definition: strings.hpp:307
std::string status
Definition: http.hpp:637
Try< Nothing > sleep(const Duration &duration)
Definition: os.hpp:219
Result< T > get() const
Definition: http.hpp:502
bool await(const Duration &duration=Seconds(-1)) const
Definition: future.hpp:1260
Future< std::vector< Future< T > > > await(const std::vector< Future< T >> &futures)
Definition: collect.hpp:309
bool await(const process::Future< T > &future, const Duration &duration)
Definition: gtest.hpp:67
Definition: stopwatch.hpp:30
constexpr char READWRITE_HTTP_AUTHENTICATION_REALM[]
Definition: gtest.hpp:36
Definition: duration.hpp:32
bool isPending() const
Definition: future.hpp:1208
inline::testing::AssertionResult AssertExitStatusEq(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:284
inline::testing::AssertionResult AwaitAssertTermSigEq(const char *expectedExpr, const char *actualExpr, const char *durationExpr, const int expected, const process::Future< Option< int >> &actual, const Duration &duration)
Definition: gtest.hpp:758
#define CHECK_SOME(expression)
Definition: check.hpp:50
bool isDiscarded() const
Definition: future.hpp:1222
std::string body
Definition: http.hpp:670
Definition: duration.hpp:193
#define CHECK_ABANDONED(expression)
Definition: check.hpp:38
const Future< T > & onAny(AnyCallback &&callback) const
Definition: future.hpp:1442
Nanoseconds elapsed() const
Definition: stopwatch.hpp:54
::testing::AssertionResult Await(const char *expr, const char *, const process::Future< T > &actual, const Duration &duration)
Definition: gtest.hpp:104
Definition: gtest.hpp:41
const Future< T > & onAbandoned(AbandonedCallback &&callback) const
Definition: future.hpp:1332
constexpr char READONLY_HTTP_AUTHENTICATION_REALM[]
Definition: gtest.hpp:35
const T & get() const &
Definition: option.hpp:119
inline::testing::AssertionResult AwaitAssertResponseBodyEq(const char *expectedExpr, const char *actualExpr, const char *durationExpr, const std::string &expected, const process::Future< process::http::Response > &actual, const Duration &duration)
Definition: gtest.hpp:464
inline::testing::AssertionResult AssertTermSigNe(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:415
inline::testing::AssertionResult AwaitAssertExited(const char *actualExpr, const char *durationExpr, const process::Future< Option< int >> &actual, const Duration &duration)
Definition: gtest.hpp:580
inline::testing::AssertionResult AwaitAssertExitStatusNe(const char *expectedExpr, const char *actualExpr, const char *durationExpr, const int expected, const process::Future< Option< int >> &actual, const Duration &duration)
Definition: gtest.hpp:668
#define CHECK_READY(expression)
Definition: check.hpp:29
::testing::AssertionResult AwaitAssertEq(const char *expectedExpr, const char *actualExpr, const char *durationExpr, const T1 &expected, const process::Future< T2 > &actual, const Duration &duration)
Definition: gtest.hpp:218
inline::testing::AssertionResult AwaitAssertResponseHeaderEq(const char *expectedExpr, const char *keyExpr, const char *actualExpr, const char *durationExpr, const std::string &expected, const std::string &key, const process::Future< process::http::Response > &actual, const Duration &duration)
Definition: gtest.hpp:513
Definition: attributes.hpp:24
static void settle()
Definition: executor.hpp:48
bool await(const Duration &duration=Seconds(-1))
inline::testing::AssertionResult AssertTermSigEq(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:383
inline::testing::AssertionResult AssertSignaled(const char *actualExpr, const int actual)
Definition: gtest.hpp:351
bool isNone() const
Definition: option.hpp:117
::testing::AssertionResult AwaitAssertFailed(const char *expr, const char *, const process::Future< T > &actual, const Duration &duration)
Definition: gtest.hpp:142
void start()
Definition: stopwatch.hpp:42
inline::testing::AssertionResult AwaitAssertExitStatusEq(const char *expectedExpr, const char *actualExpr, const char *durationExpr, const int expected, const process::Future< Option< int >> &actual, const Duration &duration)
Definition: gtest.hpp:621
const std::string & failure() const
Definition: future.hpp:1320
static void resume()
Definition: owned.hpp:36
inline::testing::AssertionResult AwaitAssertResponseStatusEq(const char *expectedExpr, const char *actualExpr, const char *durationExpr, const std::string &expected, const process::Future< process::http::Response > &actual, const Duration &duration)
Definition: gtest.hpp:414
Headers headers
Definition: http.hpp:639
::testing::AssertionResult AwaitAssertReady(const char *expr, const char *, const process::Future< T > &actual, const Duration &duration)
Definition: gtest.hpp:120
Definition: latch.hpp:24
static bool paused()
Check whether clock is currently running.
inline::testing::AssertionResult AwaitAssertSignaled(const char *actualExpr, const char *durationExpr, const process::Future< Option< int >> &actual, const Duration &duration)
Definition: gtest.hpp:717
static ClockTestEventListener * instance()
Definition: gtest.hpp:45
inline::testing::AssertionResult AwaitAssertTermSigNe(const char *expectedExpr, const char *actualExpr, const char *durationExpr, const int expected, const process::Future< Option< int >> &actual, const Duration &duration)
Definition: gtest.hpp:805
inline::testing::AssertionResult AssertExited(const char *actualExpr, const int actual)
Definition: gtest.hpp:250
bool isFailed() const
Definition: future.hpp:1229
Definition: future.hpp:58