allegro / marathon-consul

Integrates Marathon apps with Consul service discovery.
Apache License 2.0
191 stars 33 forks source link

Parallel tests run into a data race #279

Closed chemicL closed 6 years ago

chemicL commented 6 years ago

During tests I got the following report:

go test -coverprofile=coverage/marathon.coverprofile -race github.com/allegro/marathon-consul/marathon
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="127.0.0.1:56985" Protocol=HTTP error="Expected 200 but got 404 for /v2/apps" statusCode=404
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="127.0.0.1:56986" Protocol=HTTP error="Expected 200 but got 500 for /v2/apps" statusCode=500
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="127.0.0.1:56981" Protocol=HTTP error="Expected 200 but got 500 for /v2/apps//app/id" statusCode=500
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="127.0.0.1:56984" Protocol=HTTP error="Expected 200 but got 500 for " statusCode=500
time="2017-10-31T14:50:49+01:00" level=info msg="Marathon Leader mode set to resolved hostname" Leader="polpc01873:56998"
==================
WARNING: DATA RACE
Write at 0x0000017aa248 by goroutine 30:
  github.com/allegro/marathon-consul/marathon.TestIsLeader_NotPassingMyLeaderIsEmptyStringShouldFillItWithLocalHostname()
      /Users/dariusz.jedrzejczyk/development/projects/go/src/github.com/allegro/marathon-consul/marathon/marathon_test.go:403 +0x295
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:657 +0x107
Previous read at 0x0000017aa248 by goroutine 32:
  github.com/allegro/marathon-consul/marathon.(*Marathon).resolveHostname()
      github.com/allegro/marathon-consul/marathon/_test/_obj_test/marathon.go:304 +0x6a
  github.com/allegro/marathon-consul/marathon.(*Marathon).IsLeader()
      github.com/allegro/marathon-consul/marathon/_test/_obj_test/marathon.go:292 +0x22c
  github.com/allegro/marathon-consul/marathon.TestIsLeader_ShouldReturnErrorWhenCanNotParseLocation()
      /Users/dariusz.jedrzejczyk/development/projects/go/src/github.com/allegro/marathon-consul/marathon/marathon_test.go:442 +0xd8
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:657 +0x107
Goroutine 30 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:697 +0x543
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:882 +0xaa
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:657 +0x107
  testing.runTests()
      /usr/local/go/src/testing/testing.go:888 +0x4e0
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:822 +0x1c3
  main.main()
      github.com/allegro/marathon-consul/marathon/_test/_testmain.go:170 +0x33d
Goroutine 32 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:697 +0x543
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:882 +0xaa
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:657 +0x107
  testing.runTests()
      /usr/local/go/src/testing/testing.go:888 +0x4e0
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:822 +0x1c3
  main.main()
      github.com/allegro/marathon-consul/marathon/_test/_testmain.go:170 +0x33d
==================
time="2017-10-31T14:50:49+01:00" level=info msg="Marathon Leader mode set to resolved hostname" Leader="localhost:57000"
--- FAIL: TestIsLeader_ShouldReturnErrorWhenCanNotParseLocation (0.00s)
    testing.go:610: race detected during execution of test
--- FAIL: TestMarathon_TasksWhenMarathonReturnEmptyList (0.01s)
    testing.go:610: race detected during execution of test
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="127.0.0.1:56996" Protocol=HTTP error="Expected 200 but got 500 for /v2/apps/app/id/tasks" statusCode=500
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="127.0.0.1:56999" Protocol=HTTP error="Expected 200 but got 404 for /v2/apps" statusCode=404
--- FAIL: TestMarathon_TasksWhenMarathonConnectionFailedShouldNotRetry (0.00s)
    testing.go:610: race detected during execution of test
--- FAIL: TestMarathon_AppWhenMarathonReturnMalformedJsonResponse (0.00s)
    testing.go:610: race detected during execution of test
--- FAIL: TestMarathon_TasksWhenMarathonReturnEmptyResponse (0.00s)
    testing.go:610: race detected during execution of test
--- FAIL: TestIsLeader_ShouldUsePortFromMarathonConfigToConnectToLocalLeader (0.00s)
    testing.go:610: race detected during execution of test
--- FAIL: TestIsLeader_NotPassingMyLeaderIsEmptyStringShouldFillItWithLocalHostname (0.00s)
    testing.go:610: race detected during execution of test
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="not::valid/location" Protocol=HTTP error="Get http://not::valid/location/v2/apps?embed=apps.tasks&label=consul: invalid URL port ":valid"" statusCode="???"
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="127.0.0.1:57014" Protocol=HTTP error="Expected 200 but got 500 for /v2/leader" statusCode=500
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="127.0.0.1:57020" Protocol=HTTP error="Expected 200 but got 404 for /v2/apps//test/app" statusCode=404
time="2017-10-31T14:50:49+01:00" level=warning msg="Error on http request" Location="unknown:22" Protocol=HTTP error="Get http://unknown:22/v2/apps?embed=apps.tasks&label=consul: dial tcp: lookup unknown: no such host" statusCode="???"
--- FAIL: TestEventStream_PassingStreamerCreated (1.01s)
    testing.go:610: race detected during execution of test
FAIL
coverage: 91.5% of statements
FAIL    github.com/allegro/marathon-consul/marathon 1.053s
make: *** [github.com/allegro/marathon-consul/marathon] Error 1