(t *testing.T)
| 133 | } |
| 134 | |
| 135 | func (s) TestSync(t *testing.T) { |
| 136 | defer restoreHooks()() |
| 137 | |
| 138 | // Infinitely fast CPU: time doesn't pass unless sleep is called. |
| 139 | tn := time.Unix(123, 0) |
| 140 | now = func() time.Time { return tn } |
| 141 | sleep = func(d time.Duration) { tn = tn.Add(d) } |
| 142 | |
| 143 | // Simulate a 20ms latency network, then run sync across that and expect to |
| 144 | // measure 20ms latency, or 10ms additional delay for a 30ms network. |
| 145 | slowConn, err := (&Network{Kbps: 0, Latency: 20 * time.Millisecond, MTU: 5}).Conn(bufConn{&bytes.Buffer{}}) |
| 146 | if err != nil { |
| 147 | t.Fatalf("Unexpected error creating connection: %v", err) |
| 148 | } |
| 149 | c, err := (&Network{Latency: 30 * time.Millisecond}).Conn(slowConn) |
| 150 | if err != nil { |
| 151 | t.Fatalf("Unexpected error creating connection: %v", err) |
| 152 | } |
| 153 | if c.(*conn).delay != 10*time.Millisecond { |
| 154 | t.Fatalf("c.delay = %v; want 10ms", c.(*conn).delay) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | func (s) TestSyncTooSlow(t *testing.T) { |
| 159 | defer restoreHooks()() |
nothing calls this directly
no test coverage detected