Hi Petr,
That is fine:
call (session->handleResponseBody (responseBody))
.willCall (sessionStatus->trackerRequestSessionResponseRecieved (trackerResponse))
.returns()
.returns();
I’ve been thinking whether we should also check trackerResponse.failureReason() in the TrackerRequestSession and call something like trackerRequestFaildOnTrackerError(), or check only HTTP errors - there is no problem with checking HTTP errors. However, I’m not sure where to put the response check and the failure call. Now I’ve this code to handle response bodies:
Yes, definitely! If responseBody is a tracker error, then sending the error string will do:
call (session->handleResponseBody (responseBody))
.willCall (sessionStatus->trackerRequestSessionTrackerError (errorString))
.returns()
.returns();
If the torrent couldn’t be parsed, then the error string would say something like “Tracker response could not be parsed.”
1. Should I check there also tracker errors via trackerResponse.failureReason()? If so, I’d need to modify testing scenario (scenarioRecieveResponse()) to differentiate between “response was[n’t] parsed correctly” and “response has[n’t] errors”.
Normal and error scenarios may better be separate, otherwise adding further ifs in the scenarioRecieveResponse() would make it quite messy. What about having scenarioReceiveResponse(), scenarioHttpError(), scenarioTrackerError()?
2. Assuming that the answer to the previous question is “yes”, should I put the trackerRequestFaildOnTrackerError() call before the trackerRequestSessionResponseRecieved() call or after it?
I imagine them exclusive (see the expectation above). …ResponseReceived is only sent if no errors occured, if an error occured, then only a single error status message. That would simplify the state machine of the clients I think.
3. Since there is nothing to do after a response is recieved, should I also close session if a valid response (without errors) is get or only if there was some error?
Yes, it makes sense to close it explicitly.
4. As for checking HTTP request success, should I consider something else than status code == 200 as a success?
All 2xx codes are success codes. I’d treat anything >= 300 and < 200 an error and would then
call (session->handleResponseHeader (responseHeader))
.willCall (sessionStatus->trackerRequestSessionHttpError (statusCodeAndPhraseString))
.returns()
.returns();
Regards,
Peter
