| 1080 | } |
| 1081 | |
| 1082 | func TestRestCodeCoverage(t *testing.T) { |
| 1083 | _, err := ants.NewPool(-1, ants.WithExpiryDuration(-1)) |
| 1084 | require.ErrorIs(t, err, ants.ErrInvalidPoolExpiry) |
| 1085 | _, err = ants.NewPool(1, ants.WithExpiryDuration(-1)) |
| 1086 | require.ErrorIs(t, err, ants.ErrInvalidPoolExpiry) |
| 1087 | _, err = ants.NewPoolWithFunc(-1, demoPoolFunc, ants.WithExpiryDuration(-1)) |
| 1088 | require.ErrorIs(t, err, ants.ErrInvalidPoolExpiry) |
| 1089 | _, err = ants.NewPoolWithFunc(1, demoPoolFunc, ants.WithExpiryDuration(-1)) |
| 1090 | require.ErrorIs(t, err, ants.ErrInvalidPoolExpiry) |
| 1091 | _, err = ants.NewPoolWithFunc(1, nil, ants.WithExpiryDuration(-1)) |
| 1092 | require.ErrorIs(t, err, ants.ErrLackPoolFunc) |
| 1093 | _, err = ants.NewPoolWithFuncGeneric(-1, demoPoolFuncInt, ants.WithExpiryDuration(-1)) |
| 1094 | require.ErrorIs(t, err, ants.ErrInvalidPoolExpiry) |
| 1095 | _, err = ants.NewPoolWithFuncGeneric(1, demoPoolFuncInt, ants.WithExpiryDuration(-1)) |
| 1096 | require.ErrorIs(t, err, ants.ErrInvalidPoolExpiry) |
| 1097 | var fn func(i int) |
| 1098 | _, err = ants.NewPoolWithFuncGeneric(1, fn, ants.WithExpiryDuration(-1)) |
| 1099 | require.ErrorIs(t, err, ants.ErrLackPoolFunc) |
| 1100 | |
| 1101 | options := ants.Options{} |
| 1102 | options.ExpiryDuration = time.Duration(10) * time.Second |
| 1103 | options.Nonblocking = true |
| 1104 | options.PreAlloc = true |
| 1105 | poolOpts, _ := ants.NewPool(1, ants.WithOptions(options)) |
| 1106 | t.Logf("Pool with options, capacity: %d", poolOpts.Cap()) |
| 1107 | |
| 1108 | p0, _ := ants.NewPool(TestSize, ants.WithLogger(log.New(os.Stderr, "", log.LstdFlags))) |
| 1109 | defer func() { |
| 1110 | _ = p0.Submit(demoFunc) |
| 1111 | }() |
| 1112 | defer p0.Release() |
| 1113 | for i := 0; i < n; i++ { |
| 1114 | _ = p0.Submit(demoFunc) |
| 1115 | } |
| 1116 | t.Logf("pool, capacity:%d", p0.Cap()) |
| 1117 | t.Logf("pool, running workers number:%d", p0.Running()) |
| 1118 | t.Logf("pool, free workers number:%d", p0.Free()) |
| 1119 | p0.Tune(TestSize) |
| 1120 | p0.Tune(TestSize / 10) |
| 1121 | t.Logf("pool, after tuning capacity, capacity:%d, running:%d", p0.Cap(), p0.Running()) |
| 1122 | |
| 1123 | p1, _ := ants.NewPool(TestSize, ants.WithPreAlloc(true)) |
| 1124 | defer func() { |
| 1125 | _ = p1.Submit(demoFunc) |
| 1126 | }() |
| 1127 | defer p1.Release() |
| 1128 | for i := 0; i < n; i++ { |
| 1129 | _ = p1.Submit(demoFunc) |
| 1130 | } |
| 1131 | t.Logf("pre-malloc pool, capacity:%d", p1.Cap()) |
| 1132 | t.Logf("pre-malloc pool, running workers number:%d", p1.Running()) |
| 1133 | t.Logf("pre-malloc pool, free workers number:%d", p1.Free()) |
| 1134 | p1.Tune(TestSize) |
| 1135 | p1.Tune(TestSize / 10) |
| 1136 | t.Logf("pre-malloc pool, after tuning capacity, capacity:%d, running:%d", p1.Cap(), p1.Running()) |
| 1137 | |
| 1138 | p2, _ := ants.NewPoolWithFunc(TestSize, demoPoolFunc) |
| 1139 | defer func() { |