Skip to content

Commit

Permalink
server/test: close conn to create topic after creating topic
Browse files Browse the repository at this point in the history
  • Loading branch information
travisjeffery committed Sep 3, 2017
1 parent 4828840 commit 2b34f68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (s *Server) handleRequest(conn net.Conn) {
break
}
if err != nil {
// TODO: handle err
s.logger.Info("conn read failed: %s", err)
break
}
Expand Down
13 changes: 6 additions & 7 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
)

func TestBroker(t *testing.T) {
_, teardown := setup(t)
teardown := setup(t)
defer teardown()

t.Run("Sarama", func(t *testing.T) {
Expand Down Expand Up @@ -70,15 +70,14 @@ func TestBroker(t *testing.T) {
}

func BenchmarkBroker(b *testing.B) {
_, teardown := setup(b)
teardown := setup(b)
defer teardown()

config := sarama.NewConfig()
config.Version = sarama.V0_10_0_0
config.ChannelBufferSize = 1
config.Producer.Return.Successes = true
config.Producer.RequiredAcks = sarama.WaitForAll
config.Producer.Retry.Max = 10
config.Producer.Retry.Max = 3
brokers := []string{"127.0.0.1:8000"}

producer, err := sarama.NewSyncProducer(brokers, config)
Expand Down Expand Up @@ -121,7 +120,7 @@ func BenchmarkBroker(b *testing.B) {
})
}

func setup(t assert.TestingT) (*net.TCPConn, func()) {
func setup(t assert.TestingT) func() {
dataDir, err := ioutil.TempDir("", "server_test")
assert.NoError(t, err)

Expand Down Expand Up @@ -155,6 +154,7 @@ func setup(t assert.TestingT) (*net.TCPConn, func()) {

conn, err := net.DialTCP("tcp", nil, tcpAddr)
assert.NoError(t, err)
defer conn.Close()

proxy := server.NewProxy(conn)
_, err = proxy.CreateTopic("testclient", &protocol.CreateTopicRequest{
Expand All @@ -170,8 +170,7 @@ func setup(t assert.TestingT) (*net.TCPConn, func()) {
})
assert.NoError(t, err)

return conn, func() {
conn.Close()
return func() {
srv.Close()
store.Shutdown()
os.RemoveAll(dataDir)
Expand Down

0 comments on commit 2b34f68

Please sign in to comment.