revid: added some commenting to multiSender testing utilities

This commit is contained in:
Saxon 2019-03-12 17:19:47 +10:30
parent 7f73e32d4c
commit 8b93d187c6
1 changed files with 13 additions and 0 deletions

View File

@ -270,6 +270,8 @@ func TestNewMultiSender(t *testing.T) {
}
}
// dummyLoadSender is a loadSender implementation that allows us to simulate
// the behaviour of a loadSender and check that it performas as expected.
type dummyLoadSender struct {
data []byte
buf [][]byte
@ -277,15 +279,20 @@ type dummyLoadSender struct {
failHandled bool
}
// newDummyLoadSender returns a pointer to a new dummyLoadSender.
func newDummyLoadSender(fail bool) *dummyLoadSender {
return &dummyLoadSender{failOnSend: fail, failHandled: true}
}
// load takes a byte slice and assigns it to the dummyLoadSenders data slice.
func (s *dummyLoadSender) load(d []byte) error {
s.data = d
return nil
}
// send will append to dummyLoadSender's buf slice, only if failOnSend is false.
// If failOnSend is set to true, we expect that data sent won't be written to
// the buf simulating a failed send.
func (s *dummyLoadSender) send() error {
if !s.failOnSend {
s.buf = append(s.buf, s.data)
@ -294,17 +301,23 @@ func (s *dummyLoadSender) send() error {
return errSendFailed
}
// release sets dummyLoadSender's data slice to nil. data can be checked to see
// if release has been called at the right time.
func (s *dummyLoadSender) release() {
s.data = nil
}
func (s *dummyLoadSender) close() error { return nil }
// handleSendFail simply sets the failHandled flag to true. This can be checked
// to see if handleSendFail has been called by the multiSender at the right time.
func (s *dummyLoadSender) handleSendFail(err error) error {
s.failHandled = true
return nil
}
// TestMultiSenderWrite checks that we can do basic writing to multiple senders
// using the multiSender.
func TestMultiSenderWrite(t *testing.T) {
senders := []loadSender{
newDummyLoadSender(false),