about summary refs log tree commit diff
path: root/tests/gc-auto.sh
blob: de1e2cfe405974d3297cbdec287c5433f0177b99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
source common.sh

clearStore

garbage1=$(nix add-to-store --name garbage1 ./nar-access.sh)
garbage2=$(nix add-to-store --name garbage2 ./nar-access.sh)
garbage3=$(nix add-to-store --name garbage3 ./nar-access.sh)

ls -l $garbage3
POSIXLY_CORRECT=1 du $garbage3

fake_free=$TEST_ROOT/fake-free
export _NIX_TEST_FREE_SPACE_FILE=$fake_free
echo 1100 > $fake_free

expr=$(cat <<EOF
with import ./config.nix; mkDerivation {
  name = "gc-A";
  buildCommand = ''
    set -x
    [[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 3 ]]
    mkdir \$out
    echo foo > \$out/bar
    echo 1...
    sleep 2
    echo 200 > ${fake_free}.tmp1
    mv ${fake_free}.tmp1 $fake_free
    echo 2...
    sleep 2
    echo 3...
    sleep 2
    echo 4...
    [[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 1 ]]
  '';
}
EOF
)

expr2=$(cat <<EOF
with import ./config.nix; mkDerivation {
  name = "gc-B";
  buildCommand = ''
    set -x
    mkdir \$out
    echo foo > \$out/bar
    echo 1...
    sleep 2
    echo 200 > ${fake_free}.tmp2
    mv ${fake_free}.tmp2 $fake_free
    echo 2...
    sleep 2
    echo 3...
    sleep 2
    echo 4...
  '';
}
EOF
)

nix build -v -o $TEST_ROOT/result-A -L "($expr)" \
    --min-free 1000 --max-free 2000 --min-free-check-interval 1 &
pid=$!

nix build -v -o $TEST_ROOT/result-B -L "($expr2)" \
    --min-free 1000 --max-free 2000 --min-free-check-interval 1

wait "$pid"

[[ foo = $(cat $TEST_ROOT/result-A/bar) ]]
[[ foo = $(cat $TEST_ROOT/result-B/bar) ]]