From 23bce7bde6d2acbb58efb5264c4ac2477dd52ec8 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 25 Mar 2020 23:49:33 +0800 Subject: [PATCH] reduce the goroutine count for unit testing cases of package gfpool/glog --- os/gfpool/gfpool_z_unit_concurrent_test.go | 36 +++++++++++----------- os/glog/glog_z_unit_concurrent_test.go | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/os/gfpool/gfpool_z_unit_concurrent_test.go b/os/gfpool/gfpool_z_unit_concurrent_test.go index f10f2402c..c491652fc 100644 --- a/os/gfpool/gfpool_z_unit_concurrent_test.go +++ b/os/gfpool/gfpool_z_unit_concurrent_test.go @@ -32,15 +32,15 @@ func Test_ConcurrentOS(t *testing.T) { t.Assert(err, nil) } - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { _, err = f1.Write([]byte("@1234567890#")) t.Assert(err, nil) } - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { _, err = f2.Write([]byte("@1234567890#")) t.Assert(err, nil) } - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 20200) + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2200) }) gtest.C(t, func(t *gtest.T) { @@ -54,15 +54,15 @@ func Test_ConcurrentOS(t *testing.T) { t.Assert(err, nil) defer f2.Close() - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { _, err = f1.Write([]byte("@1234567890#")) t.Assert(err, nil) } - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { _, err = f2.Write([]byte("@1234567890#")) t.Assert(err, nil) } - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 20000) + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) }) gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) @@ -76,20 +76,20 @@ func Test_ConcurrentOS(t *testing.T) { defer f2.Close() s1 := "" - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { s1 += "@1234567890#" } _, err = f2.Write([]byte(s1)) t.Assert(err, nil) s2 := "" - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { s2 += "@1234567890#" } _, err = f2.Write([]byte(s2)) t.Assert(err, nil) - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 20000) + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) }) gtest.C(t, func(t *gtest.T) { @@ -105,7 +105,7 @@ func Test_ConcurrentOS(t *testing.T) { wg := sync.WaitGroup{} ch := make(chan struct{}) - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { wg.Add(1) go func() { defer wg.Done() @@ -114,7 +114,7 @@ func Test_ConcurrentOS(t *testing.T) { t.Assert(err, nil) }() } - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { wg.Add(1) go func() { defer wg.Done() @@ -125,7 +125,7 @@ func Test_ConcurrentOS(t *testing.T) { } close(ch) wg.Wait() - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 20000) + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) }) } @@ -141,15 +141,15 @@ func Test_ConcurrentGFPool(t *testing.T) { t.Assert(err, nil) defer f2.Close() - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { _, err = f1.Write([]byte("@1234567890#")) t.Assert(err, nil) } - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { _, err = f2.Write([]byte("@1234567890#")) t.Assert(err, nil) } - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 20000) + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) }) gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) @@ -164,7 +164,7 @@ func Test_ConcurrentGFPool(t *testing.T) { wg := sync.WaitGroup{} ch := make(chan struct{}) - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { wg.Add(1) go func() { defer wg.Done() @@ -173,7 +173,7 @@ func Test_ConcurrentGFPool(t *testing.T) { t.Assert(err, nil) }() } - for i := 0; i < 10000; i++ { + for i := 0; i < 1000; i++ { wg.Add(1) go func() { defer wg.Done() @@ -184,6 +184,6 @@ func Test_ConcurrentGFPool(t *testing.T) { } close(ch) wg.Wait() - t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 20000) + t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) }) } diff --git a/os/glog/glog_z_unit_concurrent_test.go b/os/glog/glog_z_unit_concurrent_test.go index 07e4cc2fe..0197cf9f4 100644 --- a/os/glog/glog_z_unit_concurrent_test.go +++ b/os/glog/glog_z_unit_concurrent_test.go @@ -18,7 +18,7 @@ import ( func Test_Concurrent(t *testing.T) { gtest.C(t, func(t *gtest.T) { - c := 10000 + c := 1000 l := glog.New() s := "@1234567890#" f := "test.log"