mirror of
https://github.com/hanzoai/s3-cli.git
synced 2026-10-30 18:23:12 +00:00
- Replace copyright headers: "MinIO, Inc." -> "Hanzo AI, Inc." across 411+ Go files - Replace "MinIO Object Storage stack" -> "Hanzo S3 stack" in all file headers - Replace all user-facing "MinIO" references -> "Hanzo S3" in Usage, help text, examples - Replace example alias "myminio" -> "mys3" throughout - Replace example endpoints play.min.io -> s3.hanzo.ai, dl.min.io -> s3.hanzo.ai - Replace doc URLs min.io -> hanzo.space - Rewrite README.md/README_zh_CN.md: product is "Hanzo S3 CLI" (the s3 command) - Update CONTRIBUTING.md, CONFLICT.md, NOTICE, code_of_conduct.md - Update all Dockerfiles: labels, entrypoints, image refs -> ghcr.io/hanzos3/cli - Update Makefile: build output, docker tags, install paths -> s3 - Update docker-buildx.sh: image tags -> ghcr.io/hanzos3/cli - DO NOT change go.mod module path or import paths (github.com/minio/mc preserved) - DO NOT change Go identifiers, SDK types, or wire protocol constants - All unit tests pass
140 lines
3.0 KiB
Go
140 lines
3.0 KiB
Go
// Copyright (c) 2015-2022 Hanzo AI, Inc.
|
|
//
|
|
// This file is part of Hanzo S3 stack
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/rjeczalik/notify"
|
|
)
|
|
|
|
func testPipeChan(inputCh, outputCh chan notify.EventInfo, totalMsgs int) error {
|
|
var wg sync.WaitGroup
|
|
|
|
msgCtnt := notify.EventInfo(nil)
|
|
|
|
// Send messages up to totalMsgs
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
for range totalMsgs {
|
|
inputCh <- msgCtnt
|
|
}
|
|
close(inputCh)
|
|
}()
|
|
|
|
// Goroutine to receive and check messages
|
|
var recvMsgs int
|
|
var recvErr error
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
defer wg.Done()
|
|
for msg := range outputCh {
|
|
recvMsgs++
|
|
if msg != msgCtnt {
|
|
recvErr = fmt.Errorf("Corrupted message, expected = `%s`, found = `%s`", msgCtnt, msg)
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
|
|
// Wait until we finish sending and receiving messages
|
|
wg.Wait()
|
|
|
|
if recvErr != nil {
|
|
return recvErr
|
|
}
|
|
|
|
// Check if all messages are received
|
|
if recvMsgs != totalMsgs {
|
|
return fmt.Errorf("unable to receive all messages, expected: %d, lost: %d", totalMsgs, totalMsgs-recvMsgs)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Testing code
|
|
|
|
func TestPipeChannel(t *testing.T) {
|
|
fastCh, slowCh := PipeChan(1000)
|
|
err := testPipeChan(fastCh, slowCh, 10*1000)
|
|
if err != nil {
|
|
t.Errorf("ERR: %v\n", err)
|
|
}
|
|
}
|
|
|
|
func TestRegularChannel(t *testing.T) {
|
|
ch := make(chan notify.EventInfo, 1000)
|
|
err := testPipeChan(ch, ch, 10*1000)
|
|
if err != nil {
|
|
t.Errorf("ERR: %v\n", err)
|
|
}
|
|
}
|
|
|
|
// Benchmark code
|
|
|
|
func benchmarkRegular(b *testing.B, msgsNum int) {
|
|
for n := 0; n < b.N; n++ {
|
|
ch := make(chan notify.EventInfo, msgsNum)
|
|
testPipeChan(ch, ch, msgsNum)
|
|
}
|
|
}
|
|
|
|
func benchmarkPipeChan(b *testing.B, msgsNum int) {
|
|
for n := 0; n < b.N; n++ {
|
|
fastCh, slowCh := PipeChan(1000)
|
|
testPipeChan(fastCh, slowCh, msgsNum)
|
|
}
|
|
}
|
|
|
|
func BenchmarkRegular1M(b *testing.B) {
|
|
benchmarkRegular(b, 1*1000*1000)
|
|
}
|
|
|
|
func BenchmarkPipeChan1M(b *testing.B) {
|
|
benchmarkPipeChan(b, 1*1000*1000)
|
|
}
|
|
|
|
func BenchmarkRegular100K(b *testing.B) {
|
|
benchmarkRegular(b, 100*1000)
|
|
}
|
|
|
|
func BenchmarkPipeChan100K(b *testing.B) {
|
|
benchmarkPipeChan(b, 100*1000)
|
|
}
|
|
|
|
func BenchmarkRegular10K(b *testing.B) {
|
|
benchmarkRegular(b, 10*1000)
|
|
}
|
|
|
|
func BenchmarkPipeChan10K(b *testing.B) {
|
|
benchmarkPipeChan(b, 10*1000)
|
|
}
|
|
|
|
func BenchmarkRegular1K(b *testing.B) {
|
|
benchmarkRegular(b, 1*1000)
|
|
}
|
|
|
|
func BenchmarkPipeChan1K(b *testing.B) {
|
|
benchmarkPipeChan(b, 1*1000)
|
|
}
|