Skip to content

Commit 548e9d7

Browse files
committed
Remove non-determinism in tests (undo FAB-839)
The changeset submitted for FAB-839 introduces some non-determinism which makes the tests in the kafka package block. To test that this is the case, checkout that changeset [1] and run the tests in the kafka package with the "-count 50" option. A quick inspection shows we may be dealing with context leakage, but I'll defer to Luis to investigate this further. Until then, this changeset disables the new test and restores the old send-replies logic of the code. It passes all tests. [1] https://gerrit.hyperledger.org/r/#/c/2043/ Change-Id: Ie29bc38288fad3c893bc332771974ec1f19b7a4b Signed-off-by: Kostas Christidis <[email protected]>
1 parent 9d3abd1 commit 548e9d7

6 files changed

+14
-40
lines changed

orderer/kafka/broadcast.go

+6-30
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/hyperledger/fabric/orderer/config"
2626
cb "github.com/hyperledger/fabric/protos/common"
2727
ab "github.com/hyperledger/fabric/protos/orderer"
28-
"golang.org/x/net/context"
2928

3029
"github.com/golang/protobuf/proto"
3130
)
@@ -142,9 +141,7 @@ func (b *broadcasterImpl) cutBlock(period time.Duration, maxSize uint) {
142141
}
143142

144143
func (b *broadcasterImpl) recvRequests(stream ab.AtomicBroadcast_BroadcastServer) error {
145-
context, cancel := context.WithCancel(context.Background())
146-
defer cancel()
147-
bsr := newBroadcastSessionResponder(context, stream, b.config.General.QueueSize)
144+
reply := new(ab.BroadcastResponse)
148145
for {
149146
msg, err := stream.Recv()
150147
if err != nil {
@@ -153,33 +150,12 @@ func (b *broadcasterImpl) recvRequests(stream ab.AtomicBroadcast_BroadcastServer
153150
}
154151

155152
b.batchChan <- msg
156-
bsr.reply(cb.Status_SUCCESS) // TODO This shouldn't always be a success
153+
reply.Status = cb.Status_SUCCESS // TODO This shouldn't always be a success
157154

158-
}
159-
}
160-
161-
func newBroadcastSessionResponder(context context.Context, stream ab.AtomicBroadcast_BroadcastServer, queueSize uint) *broadcastSessionResponder {
162-
bsr := &broadcastSessionResponder{
163-
queue: make(chan *ab.BroadcastResponse, queueSize),
164-
}
165-
go bsr.sendReplies(context, stream)
166-
return bsr
167-
}
168-
169-
func (bsr *broadcastSessionResponder) reply(status cb.Status) {
170-
bsr.queue <- &ab.BroadcastResponse{Status: status}
171-
}
172-
173-
func (bsr *broadcastSessionResponder) sendReplies(context context.Context, stream ab.AtomicBroadcast_BroadcastServer) {
174-
for {
175-
select {
176-
case reply := <-bsr.queue:
177-
if err := stream.Send(reply); err != nil {
178-
logger.Info("Cannot send broadcast reply to client")
179-
}
180-
logger.Debugf("Sent broadcast reply %v to client", reply.Status.String())
181-
case <-context.Done():
182-
return
155+
if err := stream.Send(reply); err != nil {
156+
logger.Info("Cannot send broadcast reply to client")
183157
}
158+
logger.Debugf("Sent broadcast reply %s to client", reply.Status.String())
159+
184160
}
185161
}

orderer/kafka/broadcast_mock_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func mockNewBroadcaster(t *testing.T, conf *config.TopLevel, seek int64, disk ch
2727
mb := &broadcasterImpl{
2828
producer: mockNewProducer(t, conf, seek, disk),
2929
config: conf,
30-
batchChan: make(chan *cb.Envelope, batchChanSize),
30+
batchChan: make(chan *cb.Envelope, conf.General.BatchSize),
3131
messages: [][]byte{[]byte("checkpoint")},
3232
nextNumber: uint64(seek),
3333
}

orderer/kafka/broadcast_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func TestBroadcastBatch(t *testing.T) {
139139
// then if the response queue overflows, the order should not be able
140140
// to send back a block to the client. (Sending replies and adding
141141
// messages to the about-to-be-sent block happens on the same routine.)
142-
func TestBroadcastResponseQueueOverflow(t *testing.T) {
142+
/* func TestBroadcastResponseQueueOverflow(t *testing.T) {
143143
144144
// Make sure that the response queue is less than the batch size
145145
originalQueueSize := testConf.General.QueueSize
@@ -180,7 +180,7 @@ loop:
180180
break loop // This is the success path
181181
}
182182
}
183-
}
183+
} */
184184

185185
func TestBroadcastIncompleteBatch(t *testing.T) {
186186
if testConf.General.BatchSize <= 1 {

orderer/kafka/config_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ import (
2424
)
2525

2626
var (
27-
brokerID = int32(0)
28-
oldestOffset = int64(100) // The oldest block available on the broker
29-
newestOffset = int64(1100) // The offset that will be assigned to the next block
30-
middleOffset = (oldestOffset + newestOffset - 1) / 2 // Just an offset in the middle
31-
batchChanSize = 1000 // Size of batch channel (eventually sync with FAB-821)
27+
brokerID = int32(0)
28+
oldestOffset = int64(100) // The oldest block available on the broker
29+
newestOffset = int64(1100) // The offset that will be assigned to the next block
30+
middleOffset = (oldestOffset + newestOffset - 1) / 2 // Just an offset in the middle
3231

3332
// Amount of time to wait for block processing when doing time-based tests
3433
// We generally want this value to be as small as possible so as to make tests execute faster

orderer/kafka/orderer_mock_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ func (mbs *mockBroadcastStream) Recv() (*cb.Envelope, error) {
5353
}
5454

5555
func (mbs *mockBroadcastStream) Send(reply *ab.BroadcastResponse) error {
56-
for mbs.closed {
57-
}
5856
if !mbs.closed {
5957
mbs.outgoing <- reply
6058
}

orderer/orderer.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ General:
2525
BatchSize: 10
2626

2727
# Queue Size: The maximum number of messages to allow pending from a gRPC client
28+
# This option is currently ignored for the Kafka OrdererType.
2829
QueueSize: 10
2930

3031
# Max Window Size: The maximum number of messages to for the orderer Deliver

0 commit comments

Comments
 (0)