gitee.com/h79/goutils@v1.22.10/common/system/run_test.go (about)

     1  package system
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestMainRunning(t *testing.T) {
     9  
    10  	MainRunning(func() {
    11  		exit := Exit()
    12  		for {
    13  			select {
    14  			case <-exit.Done():
    15  				return
    16  
    17  			case <-Closed():
    18  				return
    19  			}
    20  		}
    21  	})
    22  
    23  	for i := 0; i < 2000; i++ {
    24  		ChildRunning(func() {
    25  			for {
    26  				select {
    27  				case <-Closed():
    28  					t.Log("close")
    29  					return
    30  				}
    31  			}
    32  		})
    33  	}
    34  	ChildRunning(func() {
    35  		time.Sleep(time.Second * 10)
    36  		Close()
    37  	})
    38  	Go().Wait()
    39  }
    40  
    41  func TestChildRunning(t *testing.T) {
    42  	var i map[string]int
    43  	DefRecoverFunc = func(r any) {
    44  		t.Log(r)
    45  	}
    46  	ChildRunning(func() {
    47  		i["1"] = 1
    48  	})
    49  	Go().Wait()
    50  }