TestConn_UsedAtPrecision verifies that usedAt has 50ms precision (not nanosecond)
(t *testing.T)
| 223 | |
| 224 | // TestConn_UsedAtPrecision verifies that usedAt has 50ms precision (not nanosecond) |
| 225 | func TestConn_UsedAtPrecision(t *testing.T) { |
| 226 | // Create a mock connection |
| 227 | server, client := net.Pipe() |
| 228 | defer server.Close() |
| 229 | defer client.Close() |
| 230 | |
| 231 | cn := NewConn(client) |
| 232 | defer cn.Close() |
| 233 | |
| 234 | ctx := context.Background() |
| 235 | |
| 236 | // Perform an operation |
| 237 | err := cn.WithReader(ctx, time.Second, func(rd *proto.Reader) error { |
| 238 | return nil |
| 239 | }) |
| 240 | if err != nil { |
| 241 | t.Fatalf("WithReader failed: %v", err) |
| 242 | } |
| 243 | |
| 244 | // Get usedAt time |
| 245 | usedAt := cn.UsedAt() |
| 246 | |
| 247 | // Verify that usedAt has nanosecond precision (from the cached time which updates every 50ms) |
| 248 | // The value should be reasonable (not year 1970 or something) |
| 249 | if usedAt.Year() < 2020 { |
| 250 | t.Errorf("Expected usedAt to be a recent time, got %v", usedAt) |
| 251 | } |
| 252 | |
| 253 | // The nanoseconds might be non-zero depending on when the cache was updated |
| 254 | // We just verify the time is stored with full precision (not truncated to seconds) |
| 255 | initialNanos := usedAt.UnixNano() |
| 256 | if initialNanos == 0 { |
| 257 | t.Error("Expected usedAt to have nanosecond precision, got 0") |
| 258 | } |
| 259 | } |