Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WebDriverAgentLib/Routing/FBWebServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ - (void)handleException:(NSException *)exception forResponse:(RouteResponse *)re

- (void)registerServerKeyRouteHandlers
{
[self.server get:@"/health" withBlock:^(RouteRequest *request, RouteResponse *response) {
[self.server handleMethod:@"GET" withPath:@"/health" standalone:YES block:^(RouteRequest *request, RouteResponse *response) {
[response respondWithString:@"<!DOCTYPE html><html><title>Health Check</title><body><p>I-AM-ALIVE</p></body></html>"];
}];

Expand Down
23 changes: 23 additions & 0 deletions WebDriverAgentTests/UnitTests/FBHTTPServerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

#import "FBHTTPServer.h"
#import "FBTCPSocket.h"
#import "FBWebServer.h"

@interface FBWebServer (FBWDATestable)
- (void)registerServerKeyRouteHandlers;
@end

static atomic_int gFramingProbeHits;

Expand Down Expand Up @@ -230,6 +235,24 @@ - (void)testWellFormedRequestStillSucceeds
XCTAssertTrue([response containsString:@"pong"], @"%@", response);
}

- (void)testHealthRespondsWhileRouteQueueIsBlocked
{
FBWebServer *webServer = [FBWebServer new];
[webServer setValue:self.server forKey:@"server"];
[webServer registerServerKeyRouteHandlers];
dispatch_queue_t routeQueue = dispatch_queue_create("com.facebook.wda.test.health", DISPATCH_QUEUE_SERIAL);
[self.server setRouteQueue:routeQueue];
dispatch_suspend(routeQueue);
@try {
NSString *response = [self responseClosingFirstForRequest:@"GET /health HTTP/1.1\r\nHost: localhost\r\n\r\n"];
XCTAssertTrue([response hasPrefix:@"HTTP/1.1 200"], @"%@", response);
XCTAssertTrue([response hasSuffix:@"<!DOCTYPE html><html><title>Health Check</title><body><p>I-AM-ALIVE</p></body></html>"], @"%@", response);
} @finally {
dispatch_resume(routeQueue);
dispatch_sync(routeQueue, ^{});
}
}

- (void)testConnectionsTheClientClosesReleaseTheirSockets
{
// The server keeps a connection open after answering, so the client is the one that hangs up.
Expand Down
Loading