+# end-to-end test which actually uses inotify/kevent
+{
+ my $env = { PI_CONFIG => $cfg_path };
+ $git->cleanup;
+
+ # n.b. --no-scan is only intended for testing atm
+ my $wm = start_script([qw(-watch --no-scan)], $env);
+ my $eml = eml_load('t/data/0001.patch');
+ $eml->header_set('Cc', $addr);
+ my $em = PublicInbox::Emergency->new($maildir);
+ $em->prepare(\($eml->as_string));
+
+ use_ok 'PublicInbox::InboxIdle';
+ use_ok 'PublicInbox::DS';
+ my $delivered = 0;
+ my $cb = sub {
+ my ($ibx) = @_;
+ diag "message delivered to `$ibx->{name}'";
+ $delivered++;
+ };
+ PublicInbox::DS->Reset;
+ my $ii = PublicInbox::InboxIdle->new($cfg);
+ my $obj = bless \$cb, 'PublicInbox::TestCommon::InboxWakeup';
+ $cfg->each_inbox(sub { $_[0]->subscribe_unlock('ident', $obj) });
+ PublicInbox::DS->SetPostLoopCallback(sub { $delivered == 0 });
+
+ # wait for -watch to setup inotify watches
+ my $sleep = 1;
+ if (eval { require Linux::Inotify2 } && -d "/proc/$wm->{pid}/fd") {
+ my $end = time + 2;
+ my (@ino, @ino_info);
+ do {
+ @ino = grep {
+ (readlink($_)//'') =~ /\binotify\b/
+ } glob("/proc/$wm->{pid}/fd/*");
+ } until (@ino || time > $end || !tick);
+ if (scalar(@ino) == 1) {
+ my $ino_fd = (split('/', $ino[0]))[-1];
+ my $ino_fdinfo = "/proc/$wm->{pid}/fdinfo/$ino_fd";
+ while (time < $end && open(my $fh, '<', $ino_fdinfo)) {
+ @ino_info = grep(/^inotify wd:/, <$fh>);
+ last if @ino_info >= 3;
+ tick;
+ }
+ $sleep = undef if @ino_info >= 3;
+ }
+ }
+ if ($sleep) {
+ diag "waiting ${sleep}s for -watch to start up";
+ sleep $sleep;
+ }
+
+ $em->commit; # wake -watch up
+ diag 'waiting for -watch to import new message';
+ PublicInbox::DS::event_loop();
+ $wm->kill;
+ $wm->join;
+ $ii->close;
+ PublicInbox::DS->Reset;
+ my $head = $git->qx(qw(cat-file commit HEAD));
+ my $subj = $eml->header('Subject');
+ like($head, qr/^\Q$subj\E/sm, 'new commit made');
+}
+