-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement resource owner credentials (#7424)
* Implement resource owner credentials * Fix link name * get_access_token_using_* * remove headers from response * Address comments * Display timeout value in exception
- Loading branch information
1 parent
25218a5
commit 2225609
Showing
3 changed files
with
150 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "spec" | ||
|
||
private def wait_for(timeout = 5.seconds) | ||
now = Time.monotonic | ||
|
||
until yield | ||
Fiber.yield | ||
|
||
if (Time.monotonic - now) > timeout | ||
raise "server failed to start within #{timeout}" | ||
end | ||
end | ||
end | ||
|
||
# Helper method which runs *server* | ||
# 1. Spawns `server.listen` in a new fiber. | ||
# 2. Waits until `server.listening?`. | ||
# 3. Yields to the given block. | ||
# 4. Ensures the server is closed. | ||
# 5. After returning from the block, it waits for the server to gracefully | ||
# shut down before continuing execution in the current fiber. | ||
# 6. If the listening fiber raises an exception, it is rescued and re-raised | ||
# in the current fiber. | ||
def run_server(server) | ||
server_done = Channel(Exception?).new | ||
|
||
spawn do | ||
server.listen | ||
rescue exc | ||
server_done.send exc | ||
else | ||
server_done.send nil | ||
end | ||
|
||
begin | ||
wait_for { server.listening? } | ||
|
||
yield server_done | ||
ensure | ||
server.close unless server.closed? | ||
|
||
if exc = server_done.receive | ||
raise exc | ||
end | ||
end | ||
end |
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