boosting synctest & gosimnet, a channels-only network-mock

124 views
Skip to first unread message

Jason E. Aten

unread,
May 9, 2025, 7:16:59 AMMay 9
to golang-nuts
Somehow I missed it when it was first announced, so only
recently did I discover the exciting testing/synctest experiment 
available in go1.24.

If you are a fan of repeatable, deterministic tests
for tricky concurrent code... you should really check 
out synctest.

My RPC package tests go 10x faster with the fake time
of synctest in place. Niiice.

Here is the post in case you missed it the first time
around like I did. https://go.dev/blog/synctest

Caveats: one limitation of synctest is that it is kind of tricky to test network
code with it, because you aren't allowed to
talk to a "real" network. OS calls create
non-determinism. So you need a mocked or simulated
network, entirely in memory, using only channels,
for example.

I happened to need a network simulator myself for
testing my Raft implementation under partitions,
server power failures, reboots, etc... You know,
the general chaos that fault tolerant algorithms are
made for. Lacking a better alternative, I wrote one. 
If you dismissed synctest before because you didn't have a network
simulator... happy birthday. Gosimnet implements net.Conn
and can crash, reboot, and partition servers.
It's probably got bugs, I'd consider it alpha quality,
but those can be fixed.

https://github.com/glycerine/gosimnet

Enjoy.

Jason

Jason E. Aten

unread,
May 9, 2025, 9:26:58 PMMay 9
to golang-nuts
(If anyone more clever with hand illustration (or image gen AI...stable diffusion?) 
than me can contribute a better image of the Go Gopher playing with traffic, 
that would be great. While I still find it amusing, the current AI 
generated gopher is... not really satisfactory).

Reply all
Reply to author
Forward
0 new messages