Skip to content

Commit 220eb1b

Browse files
committed
fix(tests): Move wait-loop for 'inotifywait' to testhelper
Sometimes the test-suite was failing because the helper already started creating the file-structure before inotifywait was fully running. This commit makes sure that 'inotifywait' is running and gives it some additional time to setup it's watchers. We're using a hardcoded sleep (of 2 seconds) here as unfortunately github.com/pablodz/inotifywaitgo doesn't currently able to signal back when 'inotifywait' is fully initialized. Parital: #482
1 parent af1db84 commit 220eb1b

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

pkg/storage/fs/posix/testhelpers/helpers.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ package helpers
2121
import (
2222
"context"
2323
"fmt"
24+
"log"
2425
"os"
2526
"path/filepath"
27+
"strings"
2628
"time"
2729

2830
"github.com/google/uuid"
2931
"github.com/rs/zerolog"
32+
"github.com/shirou/gopsutil/process"
3033
"github.com/stretchr/testify/mock"
3134
"google.golang.org/grpc"
3235

@@ -228,6 +231,44 @@ func NewTestEnv(config map[string]interface{}) (*TestEnv, error) {
228231
if err != nil {
229232
return nil, err
230233
}
234+
235+
// If needed, wait until inotifywait is running and has setup the watches
236+
foundInotify := false
237+
if o.WatchFS {
238+
for range 15 {
239+
// Get all running processes
240+
processes, err := process.Processes()
241+
if err != nil {
242+
panic("could not get processes: " + err.Error())
243+
}
244+
245+
// Search for the process named "inotifywait"
246+
for _, p := range processes {
247+
name, err := p.Name()
248+
if err != nil {
249+
log.Println(err)
250+
continue
251+
}
252+
253+
if strings.Contains(name, "inotifywait") {
254+
// Give it some time to setup the watches
255+
logger.Debug().Msg("waiting for inotifywait to settle...")
256+
time.Sleep(5 * time.Second)
257+
foundInotify = true
258+
break
259+
}
260+
}
261+
if foundInotify {
262+
break
263+
}
264+
logger.Debug().Msg("waiting for inotifywait to start...")
265+
time.Sleep(1 * time.Second)
266+
}
267+
}
268+
if o.WatchFS && !foundInotify {
269+
return nil, fmt.Errorf("inotifywait process not found but watch_fs is enabled")
270+
}
271+
231272
aspects := aspects.Aspects{
232273
Lookup: lu,
233274
Tree: tree,
@@ -242,6 +283,7 @@ func NewTestEnv(config map[string]interface{}) (*TestEnv, error) {
242283
if err != nil {
243284
return nil, err
244285
}
286+
245287
ctx := ruser.ContextSetUser(context.Background(), owner)
246288

247289
tmpFs, _ := fs.(*decomposedfs.Decomposedfs)

pkg/storage/fs/posix/tree/tree_suite_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package tree_test
22

33
import (
4-
"log"
5-
"strings"
64
"testing"
7-
"time"
85

96
. "github.com/onsi/ginkgo/v2"
107
. "github.com/onsi/gomega"
118
helpers "github.com/opencloud-eu/reva/v2/pkg/storage/fs/posix/testhelpers"
12-
"github.com/shirou/gopsutil/process"
139
)
1410

1511
var (
@@ -27,30 +23,6 @@ var _ = SynchronizedBeforeSuite(func() {
2723
})
2824
Expect(err).ToNot(HaveOccurred())
2925

30-
Eventually(func() bool {
31-
// Get all running processes
32-
processes, err := process.Processes()
33-
if err != nil {
34-
panic("could not get processes: " + err.Error())
35-
}
36-
37-
// Search for the process named "inotifywait"
38-
for _, p := range processes {
39-
name, err := p.Name()
40-
if err != nil {
41-
log.Println(err)
42-
continue
43-
}
44-
45-
if strings.Contains(name, "inotifywait") {
46-
// Give it some time to setup the watches
47-
time.Sleep(2 * time.Second)
48-
return true
49-
}
50-
}
51-
return false
52-
}).Should(BeTrue())
53-
5426
// Set up environment with FS watching disabled
5527
non_watching_env, err = helpers.NewTestEnv(map[string]any{"watch_fs": false})
5628
Expect(err).ToNot(HaveOccurred())

0 commit comments

Comments
 (0)