-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow a wait time to be specified to allow the provider to beco…
…me available eg. when waiting for another docker container to come up
- Loading branch information
Showing
4 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'socket' | ||
require 'time' | ||
|
||
module Pact | ||
module WaitUntilServerAvailable | ||
def self.call(host, port, wait_time = 15) | ||
end_time = Time.now + wait_time | ||
tries = 0 | ||
begin | ||
sleep 2 if tries != 0 | ||
Socket.tcp(host, port, connect_timeout: 3) {} | ||
true | ||
rescue => e | ||
tries += 1 | ||
retry if Time.now < end_time | ||
return false | ||
end | ||
end | ||
|
||
def wait_until_server_available *args | ||
WaitUntilServerAvailable.call(*args) | ||
end | ||
end | ||
end |