Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Write overflow - test validating truncated writes #31

Closed

Conversation

simonferquel
Copy link
Contributor

This adds a test (that fails on current master), ensuring writes are correctly truncated by the channel, according to msize

@simonferquel
Copy link
Contributor Author

@stevvooe this test should make it easier to validate #30.
I am not completely happy with the fake net.Addr / net.Conn implementation (it is quite verbose), but it correctly exhibits the problem.

I'll do a second PR to test for read overflows.

@stevvooe
Copy link
Contributor

I am not completely happy with the fake net.Addr / net.Conn implementation (it is quite verbose), but it correctly exhibits the problem.

When mocking an interface, it is easiest to start with a stub, embedded implementation and then implement the calls required for the tests:

type mockConn struct {
  net.Conn
}

The above implements net.Conn with a nil receiver. Any calls to unimplemented methods will panic. When you want behavior, simply override the target method:

func (c *mockConn) Write(b []byte) (n int, err error) {
  c.data = append(c.data, b...)
  n = len(b)
  return n, nil
}

This looks okay. I can make some adjustments in #30 after a few fixes.

channel := newChannel(&conn, NewCodec(), testMsize)
writeRequest := MessageTwrite{1, 0, make([]byte, 2*testMsize)}
ctx := context.Background()
channel.WriteFcall(ctx, newFcall(Tag(1), writeRequest))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to check the error here.

@stevvooe
Copy link
Contributor

@simonferquel I took on this test and few others in #30. Closing.

@stevvooe stevvooe closed this Nov 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants