diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-08-02T15·07+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-08-02T16·39+0200 |
commit | ec415d7166d607c92cf8f1af688f86e4b4731dff (patch) | |
tree | c9c04c9c0a68be28f81a779f47dc6c9108b9cb66 /src/libstore/gc.cc | |
parent | 320126aeebc89f8c34ee1668ebacf1fe4b512ed8 (diff) |
Add a test for auto-GC
This currently fails because we're using POSIX file locks. So when the garbage collector opens and closes its own temproots file, it causes the lock to be released and then deleted by another GC instance.
Diffstat (limited to 'src/libstore/gc.cc')
-rw-r--r-- | src/libstore/gc.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 83cdf13a6a64..eeb2378393ae 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -871,7 +871,12 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) void LocalStore::autoGC(bool sync) { - auto getAvail = [this]() { + static auto fakeFreeSpaceFile = getEnv("_NIX_TEST_FREE_SPACE_FILE", ""); + + auto getAvail = [this]() -> uint64_t { + if (!fakeFreeSpaceFile.empty()) + return std::stoll(readFile(fakeFreeSpaceFile)); + struct statvfs st; if (statvfs(realStoreDir.c_str(), &st)) throw SysError("getting filesystem info about '%s'", realStoreDir); @@ -892,7 +897,7 @@ void LocalStore::autoGC(bool sync) auto now = std::chrono::steady_clock::now(); - if (now < state->lastGCCheck + std::chrono::seconds(5)) return; + if (now < state->lastGCCheck + std::chrono::seconds(settings.minFreeCheckInterval)) return; auto avail = getAvail(); |