Shopify/sarama — pull request #189 by eapache (2014-11-16 14:18:11+00:00)
Title: Fix test raciness

```
==================
WARNING: DATA RACE
Write by goroutine 80:
github.com/Shopify/sarama.(*MockBroker).serverLoop()
/home/eapache/src/github.com/Shopify/sarama/mockbroker.go:77 +0x219

Previous read by goroutine 38:
github.com/Shopify/sarama.(*MockBroker).Close()
/home/eapache/src/github.com/Shopify/sarama/mockbroker.go:57 +0x3a
github.com/Shopify/sarama.TestProducerFailureRetry()
/home/eapache/src/github.com/Shopify/sarama/producer_test.go:226 +0xb60
testing.tRunner()
/usr/lib/go/src/pkg/testing/testing.go:391 +0x10f

Goroutine 80 (running) created at:
github.com/Shopify/sarama.NewMockBroker()
/home/eapache/src/github.com/Shopify/sarama/mockbroker.go:154 +0x50b
github.com/Shopify/sarama.TestProducerFailureRetry()
/home/eapache/src/github.com/Shopify/sarama/producer_test.go:195 +0xa5
testing.tRunner()
/usr/lib/go/src/pkg/testing/testing.go:391 +0x10f

Goroutine 38 (running) created at:
testing.RunTests()
/usr/lib/go/src/pkg/testing/testing.go:471 +0xb3c
testing.Main()
/usr/lib/go/src/pkg/testing/testing.go:403 +0xa2
main.main()
github.com/Shopify/sarama/_test/_testmain.go:159 +0xdc
==================
```

Running the tests with -race indicated a race condition in the mockbroker around
reading/writing b.expecting. Get rid of that value entirely and just use the len
of the channel, which is simpler and less racy.

With that fixed, also fix the hang revealed in TestProducerFailureRetry due to a
mis-ordering and deferal of Close calls. We'd been getting away with it only
because of the race in the mockbroker.

Once this is merged we can do another PR to have CI run with -race.

@wvanbergen