XCTestCase+Await.mm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Example/Tests/Util/XCTestCase+Await.h"
  17. #import <Foundation/Foundation.h>
  18. // TODO(b/72864027): Reduce this to 10 seconds again once we've resolved issues with Query
  19. // Conformance Tests flakiness or gotten answers from GRPC about reconnect delays.
  20. static const double kExpectationWaitSeconds = 25.0;
  21. void LoadXCTestCaseAwait() {
  22. }
  23. @implementation XCTestCase (Await)
  24. - (void)awaitExpectations {
  25. [self waitForExpectationsWithTimeout:kExpectationWaitSeconds
  26. handler:^(NSError *_Nullable expectationError) {
  27. if (expectationError) {
  28. XCTFail(@"Error waiting for timeout: %@", expectationError);
  29. }
  30. }];
  31. }
  32. - (void)awaitExpectation:(XCTestExpectation *)expectation {
  33. [self waitForExpectations:@[ expectation ] timeout:kExpectationWaitSeconds];
  34. }
  35. - (void)awaitExpectations:(NSArray<XCTestExpectation *> *)expectations {
  36. [self waitForExpectations:expectations timeout:kExpectationWaitSeconds];
  37. }
  38. - (double)defaultExpectationWaitSeconds {
  39. return kExpectationWaitSeconds;
  40. }
  41. - (FSTVoidErrorBlock)completionForExpectationWithName:(NSString *)expectationName {
  42. XCTestExpectation *expectation = [self expectationWithDescription:expectationName];
  43. return [self completionForExpectation:expectation];
  44. }
  45. - (FSTVoidErrorBlock)completionForExpectation:(XCTestExpectation *)expectation {
  46. return ^(NSError *error) {
  47. XCTAssertNil(error);
  48. [expectation fulfill];
  49. };
  50. }
  51. @end