<commit_before># Test whether `avahi-daemon' and `libnss-mdns' work as expected.

import ./make-test.nix {

  nodes = {
    one =
      { config, pkgs, ... }: {
        services.avahi.enable = true;
        services.avahi.nssmdns = true;
      };

    two =
      { config, pkgs, ... }: {
        services.avahi.enable = true;
        services.avahi.nssmdns = true;
      };
  };

  testScript =
    '' startAll;

       # mDNS.
       $one->waitForUnit("network.target");
       $one->succeed("avahi-resolve-host-name one.local | tee out >&2");
       $one->succeed("test \"`cut -f1 < out`\" = one.local");
       $one->succeed("avahi-resolve-host-name two.local | tee out >&2");
       $one->succeed("test \"`cut -f1 < out`\" = two.local");

       $two->waitForUnit("network.target");
       $two->succeed("avahi-resolve-host-name one.local | tee out >&2");
       $two->succeed("test \"`cut -f1 < out`\" = one.local");
       $two->succeed("avahi-resolve-host-name two.local | tee out >&2");
       $two->succeed("test \"`cut -f1 < out`\" = two.local");

       # Basic DNS-SD.
       $one->succeed("avahi-browse -r -t _workstation._tcp | tee out >&2");
       $one->succeed("test `wc -l < out` -gt 0");
       $two->succeed("avahi-browse -r -t _workstation._tcp | tee out >&2");
       $two->succeed("test `wc -l < out` -gt 0");

       # More DNS-SD.
       $one->execute("avahi-publish -s \"This is a test\" _test._tcp 123 one=1 &");
       $one->sleep(5);
       $two->succeed("avahi-browse -r -t _test._tcp | tee out >&2");
       $two->succeed("test `wc -l < out` -gt 0");

       # NSS-mDNS.
       $one->succeed("getent hosts one.local >&2");
       $one->succeed("getent hosts two.local >&2");
       $two->succeed("getent hosts one.local >&2");
       $two->succeed("getent hosts two.local >&2");
    '';
}<commit_msg>nixos/tests/avahi: Fix race condition on mDNS test<commit_after># Test whether `avahi-daemon' and `libnss-mdns' work as expected.

import ./make-test.nix {

  nodes = {
    one =
      { config, pkgs, ... }: {
        services.avahi.enable = true;
        services.avahi.nssmdns = true;
      };

    two =
      { config, pkgs, ... }: {
        services.avahi.enable = true;
        services.avahi.nssmdns = true;
      };
  };

  testScript =
    '' startAll;

       # mDNS.
       $one->waitForUnit("network.target");
       $two->waitForUnit("network.target");

       $one->succeed("avahi-resolve-host-name one.local | tee out >&2");
       $one->succeed("test \"`cut -f1 < out`\" = one.local");
       $one->succeed("avahi-resolve-host-name two.local | tee out >&2");
       $one->succeed("test \"`cut -f1 < out`\" = two.local");

       $two->succeed("avahi-resolve-host-name one.local | tee out >&2");
       $two->succeed("test \"`cut -f1 < out`\" = one.local");
       $two->succeed("avahi-resolve-host-name two.local | tee out >&2");
       $two->succeed("test \"`cut -f1 < out`\" = two.local");

       # Basic DNS-SD.
       $one->succeed("avahi-browse -r -t _workstation._tcp | tee out >&2");
       $one->succeed("test `wc -l < out` -gt 0");
       $two->succeed("avahi-browse -r -t _workstation._tcp | tee out >&2");
       $two->succeed("test `wc -l < out` -gt 0");

       # More DNS-SD.
       $one->execute("avahi-publish -s \"This is a test\" _test._tcp 123 one=1 &");
       $one->sleep(5);
       $two->succeed("avahi-browse -r -t _test._tcp | tee out >&2");
       $two->succeed("test `wc -l < out` -gt 0");

       # NSS-mDNS.
       $one->succeed("getent hosts one.local >&2");
       $one->succeed("getent hosts two.local >&2");
       $two->succeed("getent hosts one.local >&2");
       $two->succeed("getent hosts two.local >&2");
    '';
}
{'fraction_non_alphanumeric': 0.20610480821177743, 'fraction_numerical': 0.01242571582928147, 'mean_word_length': 2.236888111888112, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '881197', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1352, 'n_words': 288}