Chưa có unit test cho package data (đặc biệt cho regression race) #21

Closed
opened 2026-07-22 11:26:09 +07:00 by claudecode · 1 comment
Owner

Vấn đề

Repo chưa có file test nào. Lớp internal/data (đặc biệt là Query/Reload concurrency) rất đáng có test để:

  1. Bảo vệ regression cho fix data race (issue #10).
  2. Đảm bảo query trả đúng country/ASN cho IP đã biết (vd 8.8.8.8 → US).
  3. Validate edge case (IP sai dạng, IP private, IPv6).

Fix đề xuất

  • internal/data/query_test.go: test Query("8.8.8.8") thành công, Query("not-an-ip") lỗi, IP not found.
  • internal/data/ipdb_test.go: test Reload() không leak, IsLoaded().
  • Build test có thể -race để bắt regression race.
  • Lưu ý: cloneDBFile() dùng path tương đối (data/...) → test chạy với CWD = package dir sẽ fail. Cần xử lý (chdir trong test hoặc làm path configurable) — liên quan chặt đến issue #10.

(Lưu ý phụ: data CSV/mmdb đang commit trong repo (data/), nên test có data sẵn để chạy.)

## Vấn đề Repo **chưa có file test nào**. Lớp `internal/data` (đặc biệt là `Query`/`Reload` concurrency) rất đáng có test để: 1. Bảo vệ regression cho fix data race (issue #10). 2. Đảm bảo query trả đúng country/ASN cho IP đã biết (vd 8.8.8.8 → US). 3. Validate edge case (IP sai dạng, IP private, IPv6). ## Fix đề xuất - `internal/data/query_test.go`: test `Query("8.8.8.8")` thành công, `Query("not-an-ip")` lỗi, IP not found. - `internal/data/ipdb_test.go`: test `Reload()` không leak, `IsLoaded()`. - Build test có thể `-race` để bắt regression race. - Lưu ý: `cloneDBFile()` dùng **path tương đối** (`data/...`) → test chạy với CWD = package dir sẽ fail. Cần xử lý (chdir trong test hoặc làm path configurable) — liên quan chặt đến issue #10. (Lưu ý phụ: data CSV/mmdb đang commit trong repo (`data/`), nên test có data sẵn để chạy.)
claudecode added the cleanup label 2026-07-22 11:26:09 +07:00
Author
Owner

Đã sửa trong PR #22 (merge commit 361eb40).

  • internal/data/data_test.go (mới): 4 test case
    • TestQueryValidIP8.8.8.8 → country US + network record chứa IP.
    • TestQueryInvalidIPnot-an-ip → error.
    • TestQueryNotFound240.0.0.1ErrNotFound (sentinel).
    • TestQueryReloadConcurrent — 8 goroutine Query × 5000 + 4 goroutine Reload × 30 chạy song song — regression test cho data race #10/#12.

Verify: go test -race -count=1 ./... PASS (internal/data 2.4s, không race).

Đã sửa trong PR #22 (merge commit `361eb40`). - `internal/data/data_test.go` (mới): 4 test case - `TestQueryValidIP` — `8.8.8.8` → country US + network record chứa IP. - `TestQueryInvalidIP` — `not-an-ip` → error. - `TestQueryNotFound` — `240.0.0.1` → `ErrNotFound` (sentinel). - `TestQueryReloadConcurrent` — 8 goroutine Query × 5000 + 4 goroutine Reload × 30 chạy song song — regression test cho data race #10/#12. Verify: `go test -race -count=1 ./...` PASS (`internal/data` 2.4s, không race).
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: public/ip-info#21