Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# modbus-simulator Releases

## v1.6.2

**Date:** 2026-11-16
**Previous release:** v1.6.1

No feature is added or changed.

### Changed

- Built on go-modbus v1.17.0 (was v1.16.2) (go-modbus RELEASE.md, v1.17.0).

### Tests

- `TestStress_ClientLimit` fills the client limit only once the server has freed the slot of the test harness's readiness client, which it frees on that connection's own goroutine. On a slow runner the slot could still count, and one of the two clients within the limit was turned away (3 of 200 runs under load here; 0 of 200 with the change).

---

## v1.6.1

**Date:** 2026-11-16
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/otfabric/modbus-simulator
go 1.26.0

require (
github.com/otfabric/go-modbus v1.16.2
github.com/otfabric/go-modbus v1.17.0
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.12.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxK
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/otfabric/go-modbus v1.16.2 h1:giib/sgvu+WBefxR1LCgi+eVkeqmtG2kWj5p9SI3rXs=
github.com/otfabric/go-modbus v1.16.2/go.mod h1:vPP3e6BiL8H/jwlK90htH7HLHduWhiEHx7M46QTeMcw=
github.com/otfabric/go-modbus v1.17.0 h1:fyiEC6H2XU6eeytTBOYHc9fYriIKaIhFAJ07aRsq4EQ=
github.com/otfabric/go-modbus v1.17.0/go.mod h1:vPP3e6BiL8H/jwlK90htH7HLHduWhiEHx7M46QTeMcw=
github.com/otfabric/go-serial v0.5.0 h1:hbKs9n/XLa7NnFlG3ftoNRIBsRkeS9NTO2tbqOyS1O4=
github.com/otfabric/go-serial v0.5.0/go.mod h1:CGEz7RtffVDY/EBU8oN/ydSCjMOdtRpB0LNTc8BmSUQ=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
40 changes: 35 additions & 5 deletions internal/simulator/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,24 @@ func TestStress_NoClientLimitByDefault(t *testing.T) {
func TestStress_ClientLimit(t *testing.T) {
s := startSim(t, stressFixture(), RunOptions{MaxClients: 2})
ctx := context.Background()
first, second := dialClient(t, s.port), dialClient(t, s.port)
// startSim's readiness client has closed its connection, but the server frees its
// slot on the connection's own goroutine, so it can still count against the limit
// for a moment. Fill the limit once both clients are served.
var first, second *modbus.Client
require.Eventually(t, func() bool {
a, b := servedClient(ctx, s.addr()), servedClient(ctx, s.addr())
if a != nil && b != nil {
first, second = a, b
return true
}
for _, c := range []*modbus.Client{a, b} {
if c != nil {
_ = c.Close()
}
}
return false
}, 5*time.Second, 20*time.Millisecond, "two clients within the limit were not served")
defer func() { _ = second.Close() }()
for _, c := range []*modbus.Client{first, second} {
_, err := c.ReadHoldingRegisters(ctx, 1, 0, 1)
require.NoError(t, err)
}

extra, err := rawDial(s.addr())
if err == nil {
Expand Down Expand Up @@ -338,3 +350,21 @@ func TestRun_TraceFileNotWritable(t *testing.T) {
require.ErrorContains(t, err, "create trace file")
require.ErrorIs(t, err, os.ErrNotExist)
}

// servedClient opens a client to addr and returns it once a read is served, or nil
// (closed) when the open or the read fails.
func servedClient(ctx context.Context, addr string) *modbus.Client {
c, err := modbus.New(modbus.Config{URL: "tcp://" + addr, Timeout: 300 * time.Millisecond})
if err != nil {
return nil
}
if c.Open() != nil {
_ = c.Close()
return nil
}
if _, err := c.ReadHoldingRegisters(ctx, 1, 0, 1); err != nil {
_ = c.Close()
return nil
}
return c
}
Loading