]> 127.0.0.1 Git - part/.git/commitdiff
fix
authorqydysky <32743305+qydysky@users.noreply.github.com>
Sun, 12 Mar 2023 06:03:29 +0000 (14:03 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Sun, 12 Mar 2023 06:03:29 +0000 (14:03 +0800)
.github/workflows/test.yml
msgq/Msgq_test.go

index 36dfc090e8e0099ac7b518469b1af419fa55e1bb..0f8c09364f4813ac8498ac6d05abb024b0686202 100644 (file)
@@ -23,11 +23,11 @@ jobs:
 
     - name: Test
       run: |
-        go test -v .
-        go test -v -race github.com/qydysky/part/signal
-        go test -v -race github.com/qydysky/part/reqf
-        go test -v -race github.com/qydysky/part/limit
-        go test -v -race github.com/qydysky/part/file
-        go test -v -race github.com/qydysky/part/pool
-        go test -v -race github.com/qydysky/part/funcCtrl
-        go test -v -race github.com/qydysky/part/msgq
+        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 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 30s -v -race github.com/qydysky/part/msgq
index 116ffcd6e463e51c7743b1d2786c83fc2abc5588..4b2c3f44ecf2917c41052071ebca7239f5aa89ee 100644 (file)
@@ -177,7 +177,6 @@ func Test_msgq2(t *testing.T) {
                }
                mq.Push_tag(`A3`, i)
        }
-       t.Log(`fin`)
 }
 
 func Test_msgq3(t *testing.T) {
@@ -193,18 +192,13 @@ func Test_msgq3(t *testing.T) {
                },
        })
 
-       var fin_turn = 0
-       t.Log(`start`)
        time.Sleep(time.Second)
-       for fin_turn < 1000000 {
+       for fin_turn := 0; fin_turn < 1000000; fin_turn += 1 {
                mq.Push_tag(`A1`, fin_turn)
                if fin_turn != <-mun_c {
-                       t.Error(fin_turn)
+                       t.Fatal(fin_turn)
                }
-               fin_turn += 1
-               fmt.Print("\r", fin_turn)
        }
-       t.Log(`fin`)
 }
 
 func Test_msgq4(t *testing.T) {
@@ -253,7 +247,6 @@ func Test_msgq4(t *testing.T) {
        })
 
        var fin_turn = 0
-       t.Log(`start`)
        time.Sleep(time.Second)
        for fin_turn < 5 {
                go mq.Push_tag(`A1`, `a11`)
@@ -268,9 +261,7 @@ func Test_msgq4(t *testing.T) {
                <-mun_c1
                // <-mun_c3
                fin_turn += 1
-               fmt.Print("\r", fin_turn)
        }
-       t.Log(`fin`)
 }
 
 func Test_msgq5(t *testing.T) {
@@ -320,7 +311,6 @@ func Test_msgq5(t *testing.T) {
        })
 
        var fin_turn = 0
-       t.Log(`start`)
        time.Sleep(time.Second)
        for fin_turn < 10 {
                mq.Push_tag(`A1`, `a11`)
@@ -328,9 +318,7 @@ func Test_msgq5(t *testing.T) {
                <-mun_c1
                <-mun_c2
                fin_turn += 1
-               fmt.Print("\r", fin_turn)
        }
-       t.Log(`fin`)
 }
 
 func Test_msgq6(t *testing.T) {
@@ -340,7 +328,6 @@ func Test_msgq6(t *testing.T) {
                        if b != 0 {
                                t.Fatal()
                        }
-                       t.Log(b)
                        return false
                },
        })
@@ -349,47 +336,67 @@ func Test_msgq6(t *testing.T) {
 }
 
 func Test_msgq7(t *testing.T) {
+       var c = make(chan string, 100)
        msg := NewType[int]()
        msg.Pull_tag_async_only(`1`, func(i int) (disable bool) {
                time.Sleep(time.Second)
-               t.Log(`async1`)
+               c <- "1"
                return i > 10
        })
        msg.Pull_tag_async_only(`1`, func(i int) (disable bool) {
                time.Sleep(time.Second * 2)
-               t.Log(`async2`)
+               c <- "2"
                return i > 10
        })
        msg.Pull_tag_only(`1`, func(i int) (disable bool) {
                time.Sleep(time.Second * 2)
-               t.Log(`sync1`)
+               c <- "3"
                return i > 10
        })
        msg.Pull_tag_only(`1`, func(i int) (disable bool) {
                time.Sleep(time.Second * 2)
-               t.Log(`sync2`)
+               c <- "4"
                return i > 10
        })
        msg.Push_tag(`1`, 0)
-       time.Sleep(time.Second * 10)
+       if <-c != "1" {
+               t.Fatal()
+       }
+       if <-c != "2" {
+               t.Fatal()
+       }
+       if <-c != "3" {
+               t.Fatal()
+       }
+       if <-c != "4" {
+               t.Fatal()
+       }
 }
 
 func Test_msgq8(t *testing.T) {
+       var c = make(chan string, 100)
+       var cc string
        msg := NewType[int]()
        msg.Pull_tag_async_only(`1`, func(i int) (disable bool) {
                time.Sleep(time.Second)
-               t.Logf("async %d", i)
+               c <- fmt.Sprintf("a%d", i)
                return i > 3
        })
        msg.Pull_tag_only(`1`, func(i int) (disable bool) {
                time.Sleep(time.Second)
-               t.Logf("sync %d", i)
+               c <- fmt.Sprintf("s%d", i)
                return i > 5
        })
        for i := 0; i < 20; i++ {
                msg.Push_tag(`1`, i)
        }
-       time.Sleep(time.Second * 10)
+       time.Sleep(time.Second)
+       for len(c) != 0 {
+               cc += <-c
+       }
+       if cc != "a0s0a1s1a2s2a3s3a4s4s5s6" {
+               t.Fatal()
+       }
 }
 
 // func Test_msgq6(t *testing.T) {