@CsvSource({ "IPV4_PREFERRED", "IPV6_PREFERRED" })
    @ParameterizedTest
    void resolveLessPreferredQuestionFirst(ResolvedAddressTypes resolvedAddressType) throws Exception {
        try (TestDnsServer dnsServer = new TestDnsServer(
                ImmutableMap.of(new DefaultDnsQuestion("foo.com.", DnsRecordType.A),
                                new DefaultDnsResponse(0).addRecord(DnsSection.ANSWER,
                                                                    newAddressRecord("foo.com.", "1.2.3.4")),
                                new DefaultDnsQuestion("foo.com.", DnsRecordType.AAAA),
                                new DefaultDnsResponse(0).addRecord(DnsSection.ANSWER,
                                                                    newAddressRecord("foo.com.",
                                                                                     "2001:db8::1"))),
                new ChannelInboundHandlerAdapter() {
                    @Override
                    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                        if (msg instanceof DatagramDnsQuery) {
                            final DatagramDnsQuery dnsQuery = (DatagramDnsQuery) msg;
                            final DnsRecord dnsRecord = dnsQuery.recordAt(DnsSection.QUESTION, 0);
                            if (dnsRecord.type() == DnsRecordType.AAAA) {
                                // Just release the msg and return so that the client request is timed out.
                                ReferenceCountUtil.safeRelease(msg);
                                return;
                            }
                        }
                        super.channelRead(ctx, msg);
                    }
                })) {

            final EventLoop eventLoop = CommonPools.workerGroup().next();
            final int queryTimeoutMillis = 5000;
            final DefaultDnsResolver resolver =
                    DefaultDnsResolver.of(
                            new DnsNameResolverBuilder(eventLoop)
                                    .channelType(TransportType.datagramChannelType(eventLoop))
                                    .queryTimeoutMillis(TimeUnit.HOURS.toMillis(1))
                                    .nameServerProvider(
                                            name -> DnsServerAddresses.sequential(dnsServer.addr()).stream())
                                    .build(),
                            NoopDnsCache.INSTANCE, eventLoop, ImmutableList.of(), 1,
                            queryTimeoutMillis, HostsFileEntriesResolver.DEFAULT);

            final Stopwatch stopwatch = Stopwatch.createStarted();
            final List<DefaultDnsQuestion> questions;
            if (resolvedAddressType == ResolvedAddressTypes.IPV4_PREFERRED) {
                questions = ImmutableList.of(
                        new DefaultDnsQuestion("foo.com.", DnsRecordType.A),
                        new DefaultDnsQuestion("foo.com.", DnsRecordType.AAAA));
            } else {
                questions = ImmutableList.of(
                        new DefaultDnsQuestion("foo.com.", DnsRecordType.AAAA),
                        new DefaultDnsQuestion("foo.com.", DnsRecordType.A));
            }

            // resolver.resolve() should be executed by the event loop set to DnsNameResolver.
            final CompletableFuture<List<DnsRecord>> result = eventLoop.submit(() -> {
                return resolver.resolve(questions, "");
            }).get();

            final List<DnsRecord> records = result.join();

            if (resolvedAddressType == ResolvedAddressTypes.IPV4_PREFERRED) {
                // Should not wait for AAAA to be resolved.
                assertThat(stopwatch.elapsed()).isLessThanOrEqualTo(Duration.ofMillis(queryTimeoutMillis));
            } else {
                // Should wait until AAAA is resolved.
                // The future will be completed by the timeout scheduler.
                assertThat(stopwatch.elapsed()).isGreaterThanOrEqualTo(Duration.ofMillis(queryTimeoutMillis));
            }
            assertThat(records.size()).isOne();
            final ByteArrayDnsRecord dnsRecord = (ByteArrayDnsRecord) records.get(0);
            assertThat(dnsRecord.type()).isEqualTo(DnsRecordType.A);
            assertThat(NetUtil.bytesToIpAddress(dnsRecord.content())).isEqualTo("1.2.3.4");

            resolver.close();
        }
    }
This test does not check anything but makes the future returned by
{@link DefaultDnsResolver#resolve(List, String)}} is completed even before the DNS responses
are received. By doing so, we can make our leak detectors detect any leaks if we forgot to release
the DNS responses. See https://github.com/line/armeria/pull/2951 for more information.
core/src/test/java/com/linecorp/armeria/internal/client/dns/DefaultDnsResolverTest.java