forked from goburrow/modbus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close connection when inactivity (goburrow#19)
Fixes goburrow#16
- Loading branch information
Showing
6 changed files
with
276 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package modbus | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
"time" | ||
) | ||
|
||
type nopCloser struct { | ||
io.ReadWriter | ||
|
||
closed bool | ||
} | ||
|
||
func (n *nopCloser) Close() error { | ||
n.closed = true | ||
return nil | ||
} | ||
|
||
func TestSerialCloseIdle(t *testing.T) { | ||
port := &nopCloser{ | ||
ReadWriter: &bytes.Buffer{}, | ||
} | ||
s := serialPort{ | ||
port: port, | ||
IdleTimeout: 100 * time.Millisecond, | ||
} | ||
s.lastActivity = time.Now() | ||
s.startCloseTimer() | ||
|
||
time.Sleep(150 * time.Millisecond) | ||
if !port.closed || s.port != nil { | ||
t.Fatalf("serial port is not closed when inactivity: %+v", port) | ||
} | ||
} |
Oops, something went wrong.