github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/goid/test/routinelocal_test.go (about) 1 package test 2 3 import ( 4 "context" 5 "github.com/isyscore/isc-gobase/goid/rl" 6 "testing" 7 "time" 8 ) 9 10 type myCtxKey struct { 11 } 12 13 func doSomething(t *testing.T) { 14 ctx := rl.Get() 15 v := ctx.Value(myCtxKey{}) 16 t.Logf("ctx: %v\n", v) 17 } 18 19 func TestRoutineLocal(t *testing.T) { 20 ctx := context.WithValue(context.Background(), myCtxKey{}, "233333") 21 go func(t0 *testing.T) { 22 rl.Set(ctx) 23 time.Sleep(time.Second) 24 go func(t1 *testing.T) { 25 doSomething(t1) 26 }(t0) 27 }(t) 28 time.Sleep(time.Second) 29 }