mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-19 14:31:40 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package packer
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"testing"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
// The following tests rarelly just happen. So we run them 100 times.
|
|
|
|
func TestProgressTracking_open_close(t *testing.T) {
|
|
var bar *UiProgressBar
|
|
|
|
tracker := bar.TrackProgress("1,", 1, 42, ioutil.NopCloser(nil))
|
|
tracker.Close()
|
|
|
|
tracker = bar.TrackProgress("2,", 1, 42, ioutil.NopCloser(nil))
|
|
tracker.Close()
|
|
}
|
|
|
|
func TestProgressTracking_multi_open_close(t *testing.T) {
|
|
var bar *UiProgressBar
|
|
g := errgroup.Group{}
|
|
|
|
for i := 0; i < 100; i++ {
|
|
g.Go(func() error {
|
|
tracker := bar.TrackProgress("file,", 1, 42, ioutil.NopCloser(nil))
|
|
return tracker.Close()
|
|
})
|
|
}
|
|
if err := g.Wait(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestProgressTracking_races(t *testing.T) {
|
|
var bar *UiProgressBar
|
|
g := errgroup.Group{}
|
|
|
|
for i := 0; i < 100; i++ {
|
|
g.Go(func() error {
|
|
txt := []byte("foobarbaz dolores")
|
|
b := bytes.NewReader(txt)
|
|
tracker := bar.TrackProgress("file,", 1, 42, ioutil.NopCloser(b))
|
|
|
|
for i := 0; i < 42; i++ {
|
|
tracker.Read([]byte("i"))
|
|
}
|
|
return tracker.Close()
|
|
})
|
|
}
|
|
|
|
if err := g.Wait(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|