update negentropy

This commit is contained in:
Doug Hoyte
2023-12-05 18:17:58 -05:00
parent ed0ff4fc79
commit 2262d2ac54
12 changed files with 143 additions and 20 deletions

11
test/cfgs/syncTest1.conf Normal file
View File

@ -0,0 +1,11 @@
db = "./strfry-db-test-1/"
events {
rejectEventsOlderThanSeconds = 9999999999
}
relay {
port = 40551
#logging { dumpInAll = true }
}

9
test/cfgs/syncTest2.conf Normal file
View File

@ -0,0 +1,9 @@
db = "./strfry-db-test-2/"
events {
rejectEventsOlderThanSeconds = 9999999999
}
relay {
port = 40552
}

86
test/syncTest.pl Executable file
View File

@ -0,0 +1,86 @@
#!/usr/bin/env perl
## zstdcat ../nostr-dumps/nostr-wellorder-early-500k-v1.jsonl.zst | head -100000 | perl test/syncTest.pl 1 1 10000 '{}'
use strict;
my $prob1 = shift // 1;
my $prob2 = shift // 1;
my $prob3 = shift // 98;
my $filter = shift // '{}';
{
my $total = $prob1 + $prob2 + $prob3;
die "zero prob" if $total == 0;
$prob1 = $prob1 / $total;
$prob2 = $prob2 / $total;
$prob3 = $prob3 / $total;
}
srand($ENV{SEED} || 0);
system("mkdir -p strfry-db-test-1 strfry-db-test-2");
system("rm -f strfry-db-test-1/data.mdb strfry-db-test-2/data.mdb");
my $ids1 = {};
my $ids2 = {};
{
open(my $infile1, '|-', "./strfry --config test/cfgs/syncTest1.conf import");
open(my $infile2, '|-', "./strfry --config test/cfgs/syncTest2.conf import");
while (<STDIN>) {
/"id":"(\w+)"/ || next;
my $id = $1;
my $modeRnd = rand();
if ($modeRnd < $prob1) {
print $infile1 $_;
$ids1->{$id} = 1;
} elsif ($modeRnd < $prob1 + $prob2) {
print $infile2 $_;
$ids2->{$id} = 1;
} else {
print $infile1 $_;
print $infile2 $_;
$ids1->{$id} = 1;
$ids2->{$id} = 1;
}
}
}
withRelay(sub {
system("./strfry --config test/cfgs/syncTest2.conf sync ws://127.0.0.1:40551 --dir both --filter '$filter'");
});
my $hash1 = `./strfry --config test/cfgs/syncTest1.conf export | perl test/dumbFilter.pl '$filter' | sort | sha256sum`;
my $hash2 = `./strfry --config test/cfgs/syncTest2.conf export | perl test/dumbFilter.pl '$filter' | sort | sha256sum`;
die "hashes differ" unless $hash1 eq $hash2;
print "OK.\n";
sub withRelay {
my $cb = shift;
my $relayPid = startRelay();
$cb->();
kill 'KILL', $relayPid;
wait;
}
sub startRelay {
my $pid = fork();
if (!$pid) {
exec("./strfry --config test/cfgs/syncTest1.conf relay") || die "couldn't exec strfry";
}
sleep 1; ## FIXME
return $pid;
}

View File

@ -250,7 +250,7 @@ sub doTest {
my $finalEventIds = [];
{
open(my $fh, '-|', './strfry --config test/strfry.conf export 2>/dev/null') || die "$!";
open(my $fh, '-|', './strfry --config test/cfgs/writeTest.conf export 2>/dev/null') || die "$!";
while(<$fh>) {
push @$finalEventIds, decode_json($_)->{id};
}
@ -276,7 +276,7 @@ sub addEvent {
my $eventJson = `cat test-eventXYZ.json`;
system(qq{ <test-eventXYZ.json ./strfry --config test/strfry.conf import 2>/dev/null });
system(qq{ <test-eventXYZ.json ./strfry --config test/cfgs/writeTest.conf import 2>/dev/null });
system(qq{ rm test-eventXYZ.json });