From effdedcfca10c48217b00e7f00542d1b7676f9a3 Mon Sep 17 00:00:00 2001 From: Nicolas JUHEL Date: Tue, 23 Jun 2020 09:01:21 +0200 Subject: [PATCH] Add test + fix error --- njs-ioutils/maxstdio/maxstdio.c | 4 +- njs-ioutils/maxstdio/maxstdio.o | Bin 1600 -> 916 bytes njs-progress/progress.go | 1 + test/test-progressbar/main.go | 69 ++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 test/test-progressbar/main.go diff --git a/njs-ioutils/maxstdio/maxstdio.c b/njs-ioutils/maxstdio/maxstdio.c index fd86b32d..75d6cc20 100644 --- a/njs-ioutils/maxstdio/maxstdio.c +++ b/njs-ioutils/maxstdio/maxstdio.c @@ -1,8 +1,8 @@ #include "maxstdio.h" #include -int _getmaxstdio(); -int _setmaxstdio(int new_max); +//int _getmaxstdio(); +//int _setmaxstdio(int new_max); int CGetMaxSTDIO() { return _getmaxstdio(); diff --git a/njs-ioutils/maxstdio/maxstdio.o b/njs-ioutils/maxstdio/maxstdio.o index 6517053903c8df9a9f68a4ae37ae56e6695b5c0f..059a4ae1ddf0e6abdb376de619414cebd1594fa0 100644 GIT binary patch literal 916 zcmZ`%%}T>S5T3ZH6cnsKpa+p0JhTU6n+l4jKnjhAYM}NaN{lv^fYo9GhMt6iPs7t*{ppMdc_3amI&cl4O8lG2eI1Ir+L`2?BJU;U(niGF-brpn zr-DZ?G0)N)X8+6VeJkc5L&V{S*?U*c-ja5|mK)S^W8jluQkG@1n#?2%K+I{_Dg`t; z>2v1MtA??!RLm=Txp zsS%n>(UlZcue@s)E3%&x?41(cIwrIW=Zq+YE-;C9 zBz^pus1ichKa)j;uxT7Y9rOlFB7KaSs0{udoD(TrWESFr5GHMiP@0S4i8iXH80~n1 rm3l`?-0XI{U{u|p=7ja*%E1vBb)gVQw(Ye$w%u}r0Aak9}9=G}A8{dn))%)G4Bt2x6U1%qzTA5W=7 zwyE)m+LWi`)ZQ3>`vm_xmWTWBH(viJjGs^5Rwm=mk^E(!YL2s3TxxfQJvl616Dy*$ zYz-sNdSR`K(u%My$2$5DosJC|&$h@I6^zCF{E>Hju=A|r0SZ{kCktE$-l*BSx!EAMR&T7A>u#f3ZB|-t ztGr&Xxa98mQdN-C)bm3vLUfGx128f0$w7<@5E;;MXQdaJ1G(gh9A4~%C|%u)MEEq2 zUWct5#CBJ)f&au4(jQ3@+n)4Dbi$BCw;u$4kF{Q3`l5EXy&Ouf`*w9h7sKqw|oQ(}#WD7n0ChsKi zv`O!Og%i;8U+XQdMNf53rV-Ts=&wWVuk0EJ71#6L>yF0Lxs9Yg8P_!PL&EM)m6)jc zDft$YtoeV;m_NR9Rj=lc^Q8Ai@1Iy0tI2`!ZJ;(?kN-72dzNS^X?hQihV=bUaV)F; NYf}F}s|8Kh{|0EOeQE#z diff --git a/njs-progress/progress.go b/njs-progress/progress.go index c1ec140e..30bd5c0c 100644 --- a/njs-progress/progress.go +++ b/njs-progress/progress.go @@ -64,6 +64,7 @@ type progressBar struct { type ProgressBar interface { SetSemaphoreOption(maxSimultaneous int, timeout time.Duration) NewBar(parent context.Context, options ...mpb.BarOption) Bar + NewBarSimple(name string) Bar } func NewProgressBar(timeout time.Duration, deadline time.Time, parent context.Context, options ...mpb.ContainerOption) ProgressBar { diff --git a/test/test-progressbar/main.go b/test/test-progressbar/main.go new file mode 100644 index 00000000..0cd1e7f3 --- /dev/null +++ b/test/test-progressbar/main.go @@ -0,0 +1,69 @@ +/* + * MIT License + * + * Copyright (c) 2020 Nicolas JUHEL + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +package main + +import ( + "math/rand" + "time" + + njs_progress "github.com/nabbar/golib/njs-progress" + "github.com/vbauerster/mpb/v5" +) + +var ( + pb njs_progress.ProgressBar + br njs_progress.Bar +) + +func main() { + println("Starting...") + + pb = njs_progress.NewProgressBar(0, time.Time{}, nil, mpb.WithWidth(64)) + pb.SetSemaphoreOption(0, 0) + br = pb.NewBarSimple("test bar") + + defer br.DeferMain(false) + + for i := 0; i < 1000; i++ { + + if e := br.NewWorker(); e != nil { + println("Error : " + e.Error()) + continue + } + + go func(id int) { + defer br.DeferWorker() + rand.Seed(9999) + time.Sleep(time.Duration(rand.Intn(999)) * time.Millisecond) + }(i) + } + + if e := br.WaitAll(); e != nil { + panic(e) + } + + println("finish...") +}