]> 127.0.0.1 Git - part/.git/commitdiff
Dev (#17) v0.28.20250127043311
authorqydysky <qydysky@foxmail.com>
Mon, 27 Jan 2025 04:33:00 +0000 (12:33 +0800)
committerGitHub <noreply@github.com>
Mon, 27 Jan 2025 04:33:00 +0000 (12:33 +0800)
* 1

* 1

.github/workflows/test.yml
.github/workflows/test1.yml
ctx/Ctx.go
ctx/Ctx_test.go

index b7b0d59cc757f908301fbb7606b9a4bce1462c4f..1a33cd57f131e181eab7e9d8f4746efe852c6001 100644 (file)
@@ -5,123 +5,8 @@ on:
     branches: [ master ]
 
 jobs:
-  mac-test:
-    name: mac-test
-    runs-on: macos-latest
-    steps:
-
-    - name: Set up Go 1.x
-      uses: actions/setup-go@v5
-      with:
-        go-version: '1.23'
-
-    - name: Check out code into the Go module directory
-      uses: actions/checkout@v4
-
-    - name: Test
-      run: |
-        go test -count 1 -timeout 30s -v .
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/signal
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/log
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/reqf
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/limit
-        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/file
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/pool
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/funcCtrl
-        go test -count 1 -timeout 50s -v -race github.com/qydysky/part/msgq
-        go test -count 10 -race -timeout 10s -run ^Test_3$ github.com/qydysky/part/msgq
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/sync
-        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/web
-        go test -count 1 -timeout 10s -v -run "Test_Client" -race github.com/qydysky/part/websocket
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/sql
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/rpc
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component2
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/ctx
-        go test -count 1 -timeout 7s -v -race github.com/qydysky/part/slice
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/bools
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/errors
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/crypto
-
-  w-test:
-    name: w-test
-    runs-on: windows-latest
-    steps:
-
-    - name: Set up Go 1.x
-      uses: actions/setup-go@v5
-      with:
-        go-version: '1.23'
-
-    - name: Check out code into the Go module directory
-      uses: actions/checkout@v4
-
-    - name: Test
-      run: |
-        go test -count 1 -timeout 30s -v .
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/signal
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/log
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/reqf
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/limit
-        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/file
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/pool
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/funcCtrl
-        go test -count 1 -timeout 50s -v -race github.com/qydysky/part/msgq
-        go test -count 10 -race -timeout 10s -run ^Test_3$ github.com/qydysky/part/msgq
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/sync
-        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/web
-        go test -count 1 -timeout 10s -v -run "Test_Client" -race github.com/qydysky/part/websocket
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/sql
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/rpc
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component2
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/ctx
-        go test -count 1 -timeout 7s -v -race github.com/qydysky/part/slice
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/bools
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/errors
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/crypto
-
-  u-test:
-    name: u-test
-    runs-on: ubuntu-latest
-    steps:
-
-    - name: Set up Go 1.x
-      uses: actions/setup-go@v5
-      with:
-        go-version: '1.23'
-
-    - name: Check out code into the Go module directory
-      uses: actions/checkout@v4
-
-    - name: Test
-      run: |
-        go test -count 1 -timeout 30s -v .
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/signal
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/log
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/reqf
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/limit
-        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/file
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/pool
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/funcCtrl
-        go test -count 1 -timeout 50s -v -race github.com/qydysky/part/msgq
-        go test -count 10 -race -timeout 10s -run ^Test_3$ github.com/qydysky/part/msgq
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/sync
-        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/web
-        go test -count 1 -timeout 10s -v -run "Test_Client" -race github.com/qydysky/part/websocket
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/sql
-        go test -count 1 -timeout 10s -v -race github.com/qydysky/part/rpc
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component2
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/ctx
-        go test -count 1 -timeout 7s -v -race github.com/qydysky/part/slice
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/bools
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/errors
-        go test -count 1 -timeout 5s -v -race github.com/qydysky/part/crypto
-
   test:
     name: test
-    needs: [u-test,w-test,mac-test]
     runs-on: ubuntu-latest
     steps:
     - name: Set Release Name
index 59a2861a75b79c41475d31f2de6f015a59bbb42c..5bd49c251b0be3fd212cd508216045741dbef12b 100644 (file)
@@ -37,7 +37,7 @@ jobs:
         go test -count 1 -timeout 10s -v -race github.com/qydysky/part/rpc
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component2
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/ctx
+        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/ctx
         go test -count 1 -timeout 7s -v -race github.com/qydysky/part/slice
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/bools
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/errors
@@ -75,7 +75,7 @@ jobs:
         go test -count 1 -timeout 10s -v -race github.com/qydysky/part/rpc
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component2
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/ctx
+        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/ctx
         go test -count 1 -timeout 7s -v -race github.com/qydysky/part/slice
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/bools
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/errors
@@ -113,7 +113,7 @@ jobs:
         go test -count 1 -timeout 10s -v -race github.com/qydysky/part/rpc
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/component2
-        go test -count 1 -timeout 15s -v -race github.com/qydysky/part/ctx
+        go test -count 1 -timeout 20s -v -race github.com/qydysky/part/ctx
         go test -count 1 -timeout 7s -v -race github.com/qydysky/part/slice
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/bools
         go test -count 1 -timeout 5s -v -race github.com/qydysky/part/errors
index 4f566c2df0f1601693ddaa6e7c90a61281c6dcef..62c056c40b2ecf432262900017cd6ae0ffc282ad 100644 (file)
@@ -4,6 +4,7 @@ import (
        "context"
        "errors"
        "runtime"
+       "sync"
        "sync/atomic"
        "time"
 )
@@ -85,17 +86,17 @@ func WithWait(sctx context.Context, planNum int32, to ...time.Duration) (dctx co
 // or
 // use as a normal context.WithCancel(ctx)
 func WaitCtx(ctx context.Context) (dctx context.Context, done func()) {
-       ctx1, done1 := context.WithCancel(ctx)
-       if ctxp, ok := ctx1.Value(ptr).(*Ctx); ok {
+       dctx1, done1 := context.WithCancel(ctx)
+       if ctxp, ok := dctx1.Value(ptr).(*Ctx); ok {
                ctxp.r32.Add(1)
                ctxp.w32.Add(-1)
        }
-       return ctx1, func() {
+       return dctx1, sync.OnceFunc(func() {
                done1()
-               if ctxp, ok := ctx1.Value(ptr).(*Ctx); ok {
+               if ctxp, ok := dctx1.Value(ptr).(*Ctx); ok {
                        ctxp.r32.Add(-1)
                }
-       }
+       })
 }
 
 func Done(ctx context.Context) bool {
index 0a33ff4859a7055dc39dfd948b9909ffe753d1f8..f75a775cb2ca38e39882106857b90fa1507c8ce8 100644 (file)
@@ -54,6 +54,36 @@ func TestMain5(t *testing.T) {
        }
 }
 
+func TestMain6(t *testing.T) {
+       ctx1, done := WithWait(context.Background(), 1, time.Second*2)
+       go func() {
+               ctx2, done1 := WaitCtx(ctx1)
+               go func() {
+                       time.Sleep(time.Millisecond * 500)
+                       done1()
+               }()
+               t1 := time.Now()
+               <-ctx2.Done()
+               done1()
+               if time.Since(t1)-time.Millisecond*500 > time.Millisecond*100 {
+                       t.Fatal()
+               }
+
+               ctx3, done2 := WaitCtx(ctx1)
+               defer done2()
+               <-ctx3.Done()
+               time.Sleep(time.Second)
+       }()
+       time.Sleep(time.Second)
+       t1 := time.Now()
+       if done() != nil {
+               t.Fatal()
+       }
+       if time.Since(t1) < time.Second {
+               t.Fatal()
+       }
+}
+
 func TestMain1(t *testing.T) {
        ctx1, done := WithWait(context.Background(), 1, time.Second)
        t0 := time.Now()