nameserver_quic_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package dns_test
  2. import (
  3. "context"
  4. "net/url"
  5. "testing"
  6. "time"
  7. "github.com/google/go-cmp/cmp"
  8. . "github.com/v2fly/v2ray-core/v4/app/dns"
  9. "github.com/v2fly/v2ray-core/v4/common"
  10. "github.com/v2fly/v2ray-core/v4/common/net"
  11. dns_feature "github.com/v2fly/v2ray-core/v4/features/dns"
  12. )
  13. func TestQUICNameServer(t *testing.T) {
  14. url, err := url.Parse("quic://dns.adguard.com")
  15. common.Must(err)
  16. s, err := NewQUICNameServer(url)
  17. common.Must(err)
  18. ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
  19. ips, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns_feature.IPOption{
  20. IPv4Enable: true,
  21. IPv6Enable: true,
  22. }, false)
  23. cancel()
  24. common.Must(err)
  25. if len(ips) == 0 {
  26. t.Error("expect some ips, but got 0")
  27. }
  28. }
  29. func TestQUICNameServerWithCache(t *testing.T) {
  30. url, err := url.Parse("quic://dns.adguard.com")
  31. common.Must(err)
  32. s, err := NewQUICNameServer(url)
  33. common.Must(err)
  34. ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
  35. ips, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns_feature.IPOption{
  36. IPv4Enable: true,
  37. IPv6Enable: true,
  38. }, false)
  39. cancel()
  40. common.Must(err)
  41. if len(ips) == 0 {
  42. t.Error("expect some ips, but got 0")
  43. }
  44. ctx2, cancel := context.WithTimeout(context.Background(), time.Second*2)
  45. ips2, err := s.QueryIP(ctx2, "google.com", net.IP(nil), dns_feature.IPOption{
  46. IPv4Enable: true,
  47. IPv6Enable: true,
  48. }, true)
  49. cancel()
  50. common.Must(err)
  51. if r := cmp.Diff(ips2, ips); r != "" {
  52. t.Fatal(r)
  53. }
  54. }