fork/gdu

git clone https://git.julia.blue/fork/gdu

Daniel Mildeperf: replace progress channel with atomic counters and ticker polling in all analyzers (#563)4faa51c

subvolume
2.4 KiB92 linesraw
1package analyze
2
3import (
4	"testing"
5	"time"
6
7	"github.com/dundee/gdu/v5/internal/testdir"
8	"github.com/stretchr/testify/assert"
9)
10
11func TestSequentialAnalyzerSetFollowSymlinks(t *testing.T) {
12	analyzer := CreateSeqAnalyzer()
13	analyzer.SetFollowSymlinks(true)
14	assert.True(t, analyzer.followSymlinks)
15	analyzer.SetFollowSymlinks(false)
16	assert.False(t, analyzer.followSymlinks)
17}
18
19func TestSequentialAnalyzerSetShowAnnexedSize(t *testing.T) {
20	analyzer := CreateSeqAnalyzer()
21	analyzer.SetShowAnnexedSize(true)
22	assert.True(t, analyzer.gitAnnexedSize)
23	analyzer.SetShowAnnexedSize(false)
24	assert.False(t, analyzer.gitAnnexedSize)
25}
26
27func TestSequentialAnalyzerUpdateProgress(t *testing.T) {
28	analyzer := CreateSeqAnalyzer()
29
30	// Start the progress updater
31	go analyzer.UpdateProgress()
32
33	// Set some progress via atomics
34	analyzer.progressCurrentItemName.Store("test")
35	analyzer.progressItemCount.Add(5)
36	analyzer.progressTotalUsage.Add(100)
37
38	// Wait a bit for the progress to be processed
39	time.Sleep(100 * time.Millisecond)
40
41	// Send done signal
42	analyzer.progressDoneChan <- struct{}{}
43
44	// Wait for the updater to finish
45	time.Sleep(10 * time.Millisecond)
46}
47
48func TestSequentialAnalyzerUpdateProgressWithDefaultCase(t *testing.T) {
49	analyzer := CreateSeqAnalyzer()
50
51	// Start the progress updater
52	go analyzer.UpdateProgress()
53
54	// Set some progress via atomics
55	analyzer.progressCurrentItemName.Store("test")
56	analyzer.progressItemCount.Add(5)
57	analyzer.progressTotalUsage.Add(100)
58
59	// Wait a bit for the progress to be processed
60	time.Sleep(100 * time.Millisecond)
61
62	// Update progress again
63	analyzer.progressCurrentItemName.Store("test2")
64	analyzer.progressItemCount.Add(3)
65	analyzer.progressTotalUsage.Store(50)
66
67	// Wait a bit for the progress to be processed
68	time.Sleep(100 * time.Millisecond)
69
70	// Send done signal
71	analyzer.progressDoneChan <- struct{}{}
72
73	// Wait for the updater to finish
74	time.Sleep(10 * time.Millisecond)
75}
76
77func TestSequentialAnalyzerAnalyzeDirWithIgnoreDir(t *testing.T) {
78	fin := testdir.CreateTestDir()
79	defer fin()
80
81	analyzer := CreateSeqAnalyzer()
82	dir := analyzer.AnalyzeDir(
83		"test_dir", func(name, _ string) bool { return name == "nested" }, func(_ string) bool { return false },
84	).(*Dir)
85
86	analyzer.GetDone().Wait()
87
88	assert.NotNil(t, dir)
89	assert.Equal(t, "test_dir", dir.Name)
90	// Should have fewer items since nested directory was ignored
91	assert.Less(t, dir.ItemCount, int64(5))
92}