Added more functional tests, fix bugs discovered.
* Fixed the formatting of command line logging of strawboss workers. * Fixed a bug in the (de)serialization of log levels in the strawboss service config file. * Pulled `parseBuildStatus` logic out of `loadBuildStatus` so that we could parse a JSON that didn't come from a file. * Added `parseRun` for Run objects. * Moved `/ping` to `/service/debug/ping` for symmetry with `/service/debug/stop` * Added functional tests of full builds.
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
import httpclient, json, strutils
|
||||
import httpclient, json, os, strutils, times
|
||||
|
||||
import ../../main/nim/strawbosspkg/core
|
||||
import ../../main/nim/strawbosspkg/configuration
|
||||
|
||||
proc newAuthenticatedHttpClient*(apiBase, uname, pwd: string): HttpClient =
|
||||
result = newHttpClient()
|
||||
@ -6,4 +9,38 @@ proc newAuthenticatedHttpClient*(apiBase, uname, pwd: string): HttpClient =
|
||||
assert authResp.status.startsWith("200")
|
||||
result.headers = newHttpHeaders({"Authorization": "Bearer " & parseJson(authResp.body).getStr})
|
||||
|
||||
proc waitForBuild*(client: HttpClient, apiBase, projectName, runId: string,
|
||||
expectedState = BuildState.complete,
|
||||
failedState = BuildState.failed,
|
||||
timeout = 10): Run =
|
||||
|
||||
let startTime = epochTime()
|
||||
var run: Run
|
||||
|
||||
#echo "Waiting for '" & $expectedState & "' from run:\n\t" &
|
||||
# apiBase & "/project/" & projectName & "/run/" & runId
|
||||
|
||||
while true:
|
||||
var curElapsed = epochTime() - startTime
|
||||
|
||||
#echo "Checking (" & $curElapsed & " has passed)."
|
||||
|
||||
if curElapsed > toFloat(timeout):
|
||||
raise newException(SystemError, "Timeout exceeded waiting for build.")
|
||||
|
||||
let resp = client.get(apiBase & "/project/" & projectName & "/run/" & runId)
|
||||
|
||||
#echo "Received resp:\n\n" & $resp.status & "\n\n" & $resp.body
|
||||
|
||||
if not resp.status.startsWith("200"):
|
||||
raise newException(IOError, "Unable to retrieve status. Received response: " & resp.body)
|
||||
|
||||
run = parseRun(parseJson(resp.body))
|
||||
|
||||
if run.status.state == failedState:
|
||||
raise newException(IOError, "Run transitioned to failed state '" & $failedState & "'")
|
||||
|
||||
if run.status.state == expectedState:
|
||||
return run
|
||||
|
||||
sleep(200)
|
||||
|
Reference in New Issue
Block a user