github.com/TeaOSLab/EdgeNode@v1.3.8/internal/goman/task_group_test.go (about)

     1  // Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package goman_test
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeNode/internal/goman"
     7  	"runtime"
     8  	"testing"
     9  )
    10  
    11  func TestNewTaskGroup(t *testing.T) {
    12  	var group = goman.NewTaskGroup()
    13  	var m = map[int]bool{}
    14  
    15  	for i := 0; i < runtime.NumCPU()*2; i++ {
    16  		var index = i
    17  		group.Run(func() {
    18  			t.Log("task", index)
    19  
    20  			group.Lock()
    21  			_, ok := m[index]
    22  			if ok {
    23  				t.Error("duplicated:", index)
    24  			}
    25  			m[index] = true
    26  			group.Unlock()
    27  		})
    28  	}
    29  	group.Wait()
    30  }