(t *testing.T)
| 435 | } |
| 436 | |
| 437 | func TestServerScheduling(t *testing.T) { |
| 438 | t.Parallel() |
| 439 | |
| 440 | runner := testenv.NewInProcRunner(t) |
| 441 | e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) |
| 442 | |
| 443 | emptyDir1 := testutil.TempDirectory(t) |
| 444 | emptyDir2 := testutil.TempDirectory(t) |
| 445 | |
| 446 | defer e.RunAndExpectSuccess(t, "repo", "disconnect") |
| 447 | |
| 448 | e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir, "--override-hostname=fake-hostname", "--override-username=fake-username") |
| 449 | |
| 450 | e.RunAndExpectSuccess(t, "snapshot", "create", emptyDir1) |
| 451 | e.RunAndExpectSuccess(t, "snapshot", "create", emptyDir2) |
| 452 | e.RunAndExpectSuccess(t, "maintenance", "set", "--full-interval", "2s", "--pause-full", "0s") |
| 453 | e.RunAndExpectSuccess(t, "policy", "set", emptyDir1, "--snapshot-interval=1s") |
| 454 | e.RunAndExpectSuccess(t, "policy", "set", emptyDir2, "--snapshot-interval=2s") |
| 455 | |
| 456 | var sp testutil.ServerParameters |
| 457 | |
| 458 | // maintenance info before and after server run |
| 459 | var miBefore, miAfter struct { |
| 460 | maintenance.Params |
| 461 | maintenance.Schedule `json:"schedule"` |
| 462 | } |
| 463 | |
| 464 | testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "maintenance", "info", "--json"), &miBefore) |
| 465 | |
| 466 | e.SetLogOutput(true, "server-") |
| 467 | |
| 468 | // start a server, run for 10 seconds and kill it. |
| 469 | wait, kill := e.RunAndProcessStderr(t, sp.ProcessOutput, |
| 470 | "server", "start", |
| 471 | "--address=localhost:0", |
| 472 | "--insecure", |
| 473 | "--without-password", |
| 474 | "--server-control-password=admin-pwd", |
| 475 | ) |
| 476 | |
| 477 | time.Sleep(10 * time.Second) |
| 478 | |
| 479 | kill() |
| 480 | wait() |
| 481 | |
| 482 | snaps1 := clitestutil.ListSnapshotsAndExpectSuccess(t, e, emptyDir1)[0].Snapshots |
| 483 | snaps2 := clitestutil.ListSnapshotsAndExpectSuccess(t, e, emptyDir2)[0].Snapshots |
| 484 | |
| 485 | // 10 seconds should be enough to make 8+ snapshots of emptyDir1 and 4+ snapshots of emptyDir2 |
| 486 | require.GreaterOrEqual(t, len(snaps1), 8) |
| 487 | require.GreaterOrEqual(t, len(snaps2), 4) |
| 488 | require.Less(t, len(snaps2), len(snaps1)) |
| 489 | |
| 490 | testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "maintenance", "info", "--json"), &miAfter) |
| 491 | |
| 492 | // make sure we got some maintenance runs |
| 493 | numRuns := len(miAfter.Runs["cleanup-logs"]) - len(miBefore.Runs["cleanup-logs"]) |
| 494 | require.Greater(t, numRuns, 2) |
nothing calls this directly
no test coverage detected