1// Copyright 2019 the Go-FUSE Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package fs
6
7import (
8	"context"
9	"fmt"
10	"sync"
11	"testing"
12
13	"github.com/hanwen/go-fuse/v2/fuse"
14)
15
16func TestRmChildParallel(t *testing.T) {
17	want := "hello"
18	root := &Inode{}
19	_, _, clean := testMount(t, root, &Options{
20		FirstAutomaticIno: 1,
21		OnAdd: func(ctx context.Context) {
22			n := root.EmbeddedInode()
23
24			var wg sync.WaitGroup
25			var nms []string
26			for i := 0; i < 100; i++ {
27				nms = append(nms, fmt.Sprint(i))
28			}
29			for _, nm := range nms {
30				wg.Add(1)
31				go func(nm string) {
32					ch := n.NewPersistentInode(
33						ctx,
34						&MemRegularFile{
35							Data: []byte(want),
36							Attr: fuse.Attr{
37								Mode: 0464,
38							},
39						},
40						StableAttr{})
41					n.AddChild(nm, ch, false)
42					wg.Done()
43				}(nm)
44			}
45			for _, nm := range nms {
46				wg.Add(1)
47				go func(nm string) {
48					n.RmChild(nm)
49					wg.Done()
50				}(nm)
51			}
52
53			wg.Wait()
54		},
55	})
56	defer clean()
57}
58