trees: show its phases as N of M, with progress, elapsed time and ETA (closes #113)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
trees now runs in four phases, open, read, group and write, each under the progress display scan uses, from the line naming the database to the summary line. open covers a wait on a busy database. read counts the records first, as scan's load does, then reads them against that count; group counts the directories, and write the groups. The display gains a unit so that each rate names what its phase counts; every scan phase passes files and prints as before. The tests that pinned trees' stderr now allow the phase lines between the database line and the summary. Judgement call: opening the database is a phase of its own, so there are four phases, not the three the issue sketches. Judgement call: the count and the read are separate queries, as in scan's load, so during a scan the read can end slightly past or short of its total. Model: opus-5-5
This commit is contained in:
+21
-8
@@ -303,8 +303,15 @@ func TestRunMissingDatabaseIsFatal(t *testing.T) {
|
||||
t.Errorf("run(%s) = %d, want %d", name, code, exitFatal)
|
||||
}
|
||||
|
||||
// trees shows its open phase, as it starts and as it ends,
|
||||
// before the error.
|
||||
opening := ""
|
||||
if name == cmdTrees {
|
||||
opening = treesOpenLine + "\n" + treesOpenLine + "\n"
|
||||
}
|
||||
|
||||
want := name + ": database " + path + " (from " + databaseEnv +
|
||||
")\n" +
|
||||
")\n" + opening +
|
||||
"sfdupes: " + path + ": no database (run \"sfdupes " +
|
||||
"scan\" first, or set " + databaseEnv + ")\n"
|
||||
if got := stderr(); got != want {
|
||||
@@ -506,7 +513,7 @@ func TestRunNamesDefaultDatabase(t *testing.T) {
|
||||
// nothing here may create or read one: scan gets an operand that
|
||||
// does not exist, which stops it before it takes the lock, and
|
||||
// report and trees a cancelled context, which stops them before
|
||||
// they read anything.
|
||||
// they read anything. trees shows its open phase after the line.
|
||||
t.Setenv(databaseEnv, "")
|
||||
|
||||
// Whether scan calls the database new depends on that machine too.
|
||||
@@ -540,7 +547,8 @@ func TestRunNamesDefaultDatabase(t *testing.T) {
|
||||
run: func() error {
|
||||
return runTrees(cancelledContext(t), io.Discard)
|
||||
},
|
||||
want: "trees: database " + defaultDatabasePath + " (default)\n",
|
||||
want: "trees: database " + defaultDatabasePath + " (default)\n" +
|
||||
treesOpenLine + "\n" + treesOpenLine + "\n",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -942,11 +950,16 @@ func TestRunTreesSucceeds(t *testing.T) {
|
||||
t.Errorf("stdout = %q, want %q", got, want)
|
||||
}
|
||||
|
||||
want = "trees: database " + path + " (from " + databaseEnv + ")\n" +
|
||||
"trees: 2 records read, 1 duplicate tree groups, 1 dupe trees, " +
|
||||
"300 B reclaimable\n"
|
||||
if got := stderr(); got != want {
|
||||
t.Errorf("stderr = %q, want %q", got, want)
|
||||
// Its phases come between the two lines; see
|
||||
// TestRunTreesProgressNamesEachPhase.
|
||||
first := "trees: database " + path + " (from " + databaseEnv + ")\n"
|
||||
last := "\ntrees: 2 records read, 1 duplicate tree groups, " +
|
||||
"1 dupe trees, 300 B reclaimable\n"
|
||||
|
||||
if got := stderr(); !strings.HasPrefix(got, first) ||
|
||||
!strings.HasSuffix(got, last) {
|
||||
t.Errorf("stderr = %q, want it to start %q and end %q",
|
||||
got, first, last)
|
||||
}
|
||||
|
||||
assertNoSidecars(t, path)
|
||||
|
||||
Reference in New Issue
Block a user