-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preserve buffer on reconnect() AND reconnect on connection reset by peer #291
Conversation
f65caa1
to
5276f4e
Compare
5276f4e
to
476afe4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, though I'll defer to @MattAitchison on golang usage ;)
adapters/syslog/syslog_test.go
Outdated
// Read from connection | ||
go func() { | ||
defer close(ch) | ||
defer close(dchan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick
defer func() {
close(ch)
close(chan)
} ()
adapters/syslog/syslog_test.go
Outdated
done := make(chan bool) | ||
go func() { | ||
defer close(logstream) | ||
defer close(done) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar nitpick on grouping defer into func
} | ||
} | ||
|
||
func TestSyslogReconnectOnClose(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is pretty intense.
I'd recommend breaking it down a little. Maybe move the go func()
to named functions so they're just go someReallyClearFuncName()
Would make things a little more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
476afe4
to
67bddd8
Compare
adapters/syslog/syslog_test.go
Outdated
select { | ||
case <-done: | ||
if maxMsgCount-1 != len(datac) { | ||
t.Errorf("expected %v got %v", maxMsgCount-1, len(datac)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check for duplicate messages in addition to msg count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
67bddd8
to
bf6dbd3
Compare
bf6dbd3
to
43c0db0
Compare
db840d1
to
2c4cf36
Compare
2c4cf36
to
ea5f535
Compare
testutil/mockconn.go
Outdated
|
||
// NewConn returns a new testutil.Conn | ||
func NewConn() *Conn { | ||
// A connection consists of two pipes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since a net.Pipe is a ReadWriter, it represents a duplex channel. I'm not sure you need two of these, which means you probably don't need a lot of the other code you have around these.
testutil/testutil.go
Outdated
// LocalTCPServer tcp server for testing specific network errors | ||
type LocalTCPServer struct { | ||
lnmu sync.RWMutex | ||
MockConn *Conn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach of mocking net connections is actually not terribly idiomatic. Because it's relatively easy in Go, most network tests in Go actually stand up a full network client/server instead of building mocks. This reduces a lot of code and better represents reality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. If we can force specific connection errors (i.e. timeouts/resets/etc) then we can abandon this approach for sure. I'm playing with some stuff @MattAitchison sent over to see if we can use a "normal" net.Conn
object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to. And specific errors are specific cases for specific tests, which can minimally mock what's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of should happening here. Feel free to chime in with specific pointers.....
@progrium @MattAitchison updated this per our discussion |
When is this expected to get pushed up to |
This is v3.2.1 and latest now |
make test-direct
locally with it on. ref: race: not working with Alpine based image golang/go#14481turns out that in linux (alpine at least) a
conn.Close()
shows up as asyscall.ECONNRESET
. so i included #287 here as wellcloses #287 #277 #268 #253 #215 #107