7

I've got a simple class making a HTTP POST request (to a Neo4j server, but that shouldn't matter) using URLSession, and an integration test that tests that it succeeds.

Through Xcode, via the iOS simulator, I can run this test a million times - it succeeds every time.

However, when I run swift test on Ubuntu Linux (I use the docker image provided by IBM) then I very often will get a test failure saying I got a 401 response.

Replicating that via cURL in the container does not fail at all, so I do not believe this to be a problem with my container.

I have added a packet dump (that I inspect via Charles Proxy) where our of 15 test runs, 7 test runs (and thus 7 requests) fail. All of the failed requests complain that no authentication header was supplied. And from the dump, that is correct, the dump does not contain the authentication header for those requests that fail. But why not? In fact, all of the header flags are different: a successful run has these headers:

POST /db/data/cypher HTTP/1.1
Host: 192.168.0.18:7474
Accept-Encoding: deflate, gzip
Authorization: Basic bmVvNGo6c3RhY2swdmVyRmxvdw==
Content-Type: application/json; charset=utf-8
Accept: application/json; charset=utf-8
Connection: keep-alive
User-Agent: urlsessionTestPackageTests.xctest (unknown version) curl/7.35.0
Content-Length: 135

while an unsuccessful one has these:

POST /db/data/cypher HTTP/1.1
Host: 192.168.0.18:7474
Accept: */*
Accept-Encoding: deflate, gzip
Connection: keep-alive
User-Agent: urlsessionTestPackageTests.xctest (unknown version) curl/7.35.0
Content-Length: 135

All the 200 results have the same headers, and all the 401 results have the same headers. Can you see anything in my code that should warrant such a random request?

shallowThought
  • 16,998
  • 6
  • 55
  • 100
niklassaers
  • 7,810
  • 18
  • 90
  • 141
  • Seems similar to http://stackoverflow.com/questions/41229814/httpadditionalheaders-not-working-on-linux - the container Swift version is 3.0.1 – niklassaers Jan 12 '17 at 13:07
  • I updated to Swift 3.0.2, still same error. So I adjusted the code as suggested above, and got only 5 errors out of 62 requests. Much better, but it still fails and I still don't know why. – niklassaers Jan 12 '17 at 13:46
  • Issue persists with the now official Docker image with 16.04: https://github.com/swiftdocker/docker-swift – niklassaers Jan 23 '17 at 11:52

0 Answers0