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