1515package ouroboros_test
1616
1717import (
18- ouroboros "github.com/blinklabs-io/gouroboros "
18+ "fmt "
1919 "testing"
20+
21+ ouroboros "github.com/blinklabs-io/gouroboros"
22+ "github.com/blinklabs-io/gouroboros/internal/test/ouroboros_mock"
2023)
2124
2225// Ensure that we don't panic when closing the Ouroboros object after a failed Dial() call
@@ -32,3 +35,36 @@ func TestDialFailClose(t *testing.T) {
3235 // Close Ouroboros connection
3336 oConn .Close ()
3437}
38+
39+ func TestDoubleClose (t * testing.T ) {
40+ mockConn := ouroboros_mock .NewConnection (
41+ []ouroboros_mock.ConversationEntry {
42+ ouroboros_mock .ConversationEntryHandshakeRequestGeneric ,
43+ ouroboros_mock .ConversationEntryHandshakeResponse ,
44+ },
45+ )
46+ oConn , err := ouroboros .New (
47+ ouroboros .WithConnection (mockConn ),
48+ ouroboros .WithNetworkMagic (ouroboros_mock .MockNetworkMagic ),
49+ )
50+ if err != nil {
51+ t .Fatalf ("unexpected error when creating Ouroboros object: %s" , err )
52+ }
53+ // Async error handler
54+ go func () {
55+ err , ok := <- oConn .ErrorChan ()
56+ if ! ok {
57+ return
58+ }
59+ // We can't call t.Fatalf() from a different Goroutine, so we panic instead
60+ panic (fmt .Sprintf ("unexpected Ouroboros connection error: %s" , err ))
61+ }()
62+ // Close Ouroboros connection
63+ if err := oConn .Close (); err != nil {
64+ t .Fatalf ("unexpected error when closing Ouroboros object: %s" , err )
65+ }
66+ // Close Ouroboros connection again
67+ if err := oConn .Close (); err != nil {
68+ t .Fatalf ("unexpected error when closing Ouroboros object again: %s" , err )
69+ }
70+ }
0 commit comments