(t *testing.T)
| 1732 | } |
| 1733 | |
| 1734 | func TestLastErrorNoRace(t *testing.T) { |
| 1735 | s := RunDefaultServer() |
| 1736 | defer s.Shutdown() |
| 1737 | |
| 1738 | // Access LastError in disconnection and closed handlers to make sure |
| 1739 | // that there is no race. It is possible in some cases that |
| 1740 | // nc.LastError() returns a non nil error. We don't care here about the |
| 1741 | // returned value. |
| 1742 | dch := func(c *nats.Conn) { |
| 1743 | c.LastError() |
| 1744 | } |
| 1745 | closedCh := make(chan struct{}) |
| 1746 | cch := func(c *nats.Conn) { |
| 1747 | c.LastError() |
| 1748 | closedCh <- struct{}{} |
| 1749 | } |
| 1750 | nc, err := nats.Connect(nats.DefaultURL, |
| 1751 | nats.DisconnectHandler(dch), |
| 1752 | nats.ClosedHandler(cch), |
| 1753 | nats.MaxReconnects(-1), |
| 1754 | nats.ReconnectWait(5*time.Millisecond), |
| 1755 | nats.ReconnectJitter(0, 0)) |
| 1756 | if err != nil { |
| 1757 | t.Fatalf("Unable to connect: %v\n", err) |
| 1758 | } |
| 1759 | defer nc.Close() |
| 1760 | |
| 1761 | // Restart the server several times to trigger a reconnection. |
| 1762 | for i := 0; i < 10; i++ { |
| 1763 | s.Shutdown() |
| 1764 | time.Sleep(10 * time.Millisecond) |
| 1765 | s = RunDefaultServer() |
| 1766 | } |
| 1767 | nc.Close() |
| 1768 | s.Shutdown() |
| 1769 | select { |
| 1770 | case <-closedCh: |
| 1771 | case <-time.After(5 * time.Second): |
| 1772 | t.Fatal("Timeout waiting for the closed callback") |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | type customDialer struct { |
| 1777 | ch chan bool |
nothing calls this directly
no test coverage detected