github.com/songzhibin97/gkit@v1.2.13/egroup/liftcycle_test.go (about)

     1  package egroup
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  	"testing"
     8  
     9  	"github.com/songzhibin97/gkit/goroutine"
    10  )
    11  
    12  var _admin = NewLifeAdmin()
    13  
    14  func TestLifeAdmin_Start(t *testing.T) {
    15  	srv := &http.Server{
    16  		Addr: ":8080",
    17  	}
    18  	_admin.Add(Member{
    19  		Start: func(ctx context.Context) error {
    20  			t.Log("http start")
    21  			return goroutine.Delegate(ctx, -1, func(ctx context.Context) error {
    22  				return srv.ListenAndServe()
    23  			})
    24  		},
    25  		Shutdown: func(ctx context.Context) error {
    26  			t.Log("http shutdown")
    27  			return srv.Shutdown(context.Background())
    28  		},
    29  	})
    30  	//_admin.Add(Member{
    31  	//	Start: func(ctx context.Context) error {
    32  	//		time.Sleep(5 * time.Second)
    33  	//		t.Log("error")
    34  	//		return errors.New("error")
    35  	//	},
    36  	//})
    37  	fmt.Println("error", _admin.Start())
    38  	defer _admin.shutdown()
    39  }