{"action":"created","issue":{"url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/153","repository_url":"https://api.github.com/repos/bustoutsolutions/siesta","labels_url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/153/labels{/name}","comments_url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/153/comments","events_url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/153/events","html_url":"https://github.com/bustoutsolutions/siesta/issues/153","id":192588308,"number":153,"title":"Test with Siesta changed behavoir","user":{"login":"jordanpwood","id":6576194,"avatar_url":"https://avatars.githubusercontent.com/u/6576194?v=3","gravatar_id":"","url":"https://api.github.com/users/jordanpwood","html_url":"https://github.com/jordanpwood","followers_url":"https://api.github.com/users/jordanpwood/followers","following_url":"https://api.github.com/users/jordanpwood/following{/other_user}","gists_url":"https://api.github.com/users/jordanpwood/gists{/gist_id}","starred_url":"https://api.github.com/users/jordanpwood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordanpwood/subscriptions","organizations_url":"https://api.github.com/users/jordanpwood/orgs","repos_url":"https://api.github.com/users/jordanpwood/repos","events_url":"https://api.github.com/users/jordanpwood/events{/privacy}","received_events_url":"https://api.github.com/users/jordanpwood/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-30T15:03:09Z","updated_at":"2016-11-30T15:59:23Z","closed_at":null,"body":"I have a test which exercises Siesta and the persistent cache that I wrote that Siesta uses.  Today I noticed that this test is failing, when it used to work.  In the test I setup a resource, call loadIfNeeded, then when I get a .newData with the event source .network (the actual network call uses URL mocking), I wipe the resource, and then wait for another .newData with a source of .wipe, then load the resource again.  I expect this to get data from my cache which got populated by the first load.  However, it seems that the resource is making a new request before the cache has returned a result.  Is that expected?  Is there supposed to be a race between the request and the cache hit, and I just got lucky before?  If so, got any suggestions on how to change my test?"},"comment":{"url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/comments/263911598","html_url":"https://github.com/bustoutsolutions/siesta/issues/153#issuecomment-263911598","issue_url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/153","id":263911598,"user":{"login":"pcantrell","id":378162,"avatar_url":"https://avatars.githubusercontent.com/u/378162?v=3","gravatar_id":"","url":"https://api.github.com/users/pcantrell","html_url":"https://github.com/pcantrell","followers_url":"https://api.github.com/users/pcantrell/followers","following_url":"https://api.github.com/users/pcantrell/following{/other_user}","gists_url":"https://api.github.com/users/pcantrell/gists{/gist_id}","starred_url":"https://api.github.com/users/pcantrell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcantrell/subscriptions","organizations_url":"https://api.github.com/users/pcantrell/orgs","repos_url":"https://api.github.com/users/pcantrell/repos","events_url":"https://api.github.com/users/pcantrell/events{/privacy}","received_events_url":"https://api.github.com/users/pcantrell/received_events","type":"User","site_admin":false},"created_at":"2016-11-30T15:59:22Z","updated_at":"2016-11-30T15:59:22Z","body":"> Is there supposed to be a race between the request and the cache hit\r\n\r\nYes, in a word. The `.newData(.wipe)` [is synchronous](https://github.com/bustoutsolutions/siesta/blob/master/Source/Siesta/Resource/Resource.swift#L628), but the cache read [is asynchronous](https://github.com/bustoutsolutions/siesta/blob/master/Source/Siesta/Pipeline/PipelineProcessing.swift#L71) — as is the network request, of course. That’s why, after receiving a cache hit, Siesta [checks whether the resource already has data](https://github.com/bustoutsolutions/siesta/blob/master/Source/Siesta/Resource/Resource.swift#L657) and if so ignores the cached data.\r\n\r\nThis means that you can see two different sequences of events depending on whether the network or the cache wins the race:\r\n\r\n**Cache wins**\r\n1. `.newData(.wipe)`\r\n2. `.newData(.cache)`\r\n3. `.newData(.network)`\r\n\r\n**Network wins**\r\n\r\n1. `.newData(.wipe)`\r\n2. `.newData(.network)`\r\n3. (cache hit ignored)\r\n\r\nIn real apps, the cache is very likely to beat the network, but I can imagine a mocked network winning. The solution to your problem is to pause the mocked network response until you see the cache hit. That’s something the Siesta specs have to do a lot of — and unfortunately I had to [fork Nocilla](https://github.com/luisobo/Nocilla/pull/125) to do!"}}
{"actor":{"display_login":"pcantrell"}}