You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: output_test.go
    path of file: ./repos/k6/output/influxdb
    
    the code of the file until where you have to start completion: package influxdb

import (
	"bytes"
	"context"
	"io"
	"net"
	"net/http"
	"net/http/httptest"
	"sync"
	"sync/atomic"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"go.k6.io/k6/lib/testutils"
	"go.k6.io/k6/metrics"
	"go.k6.io/k6/output"
)

func TestBadConcurrentWrites(t *testing.T) {
	t.Parallel()
	logger := testutils.NewLogger(t)
	t.Run("0", func(t *testing.T) {
		t.Parallel()
		_, err := New(output.Params{
			Logger:         logger,
			ConfigArgument: "?concurrentWrites=0",
		})
		require.Error(t, err)
		require.Equal(t, err.Error(), "influxdb's ConcurrentWrites must be a posi
    
func TestOutputFlushMetricsConcurrency(t *testing.T) {
	t.Parallel()

	var (
		requests = int32(0)
		block    = make(chan struct{})
	)

	wg := sync.WaitGroup{}
	ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		// block all the received requests
		// so concurrency will be needed
		// to not block the flush
		atomic.AddInt32(&requests, 1)
		wg.Done()
		block <- struct{}{}
	}))
	defer func() {
		// unlock the server
		for i := 0; i < 4; i++ {
			<-block
		}
		close(block)
		ts.Close()
	}()

	registry := metrics.NewRegistry()
	metric, err := registry.NewMetric("test_gauge", metrics.Gauge)
	require.NoError(t, err)

	o, err := newOutput(output.Params{
		Logger:         testutils.NewLogger(t),
		ConfigArgument: ts.URL,
	})
	require.NoError(t, err)

	for i := 0; i < 5; i++ {
		select {
		case o.semaphoreCh <- struct{}{}:
			<-o.semaphoreCh
			wg.Add(1)
			o.AddMetricSamples([]metrics.SampleContainer{metrics.Samples{
				metrics.Sample{
					TimeSeries: metrics.TimeSeries{
						Metric: metric,
						Tags:   registry.RootTagSet(),
					},
					Time:  time.Now(),
					Value: 2.0,
				},
			}})
			o.flushMetrics()
		default:
			// the 5th request should be rate limited
			assert.Equal(t, 5, i+1)
		}
	}
	wg.Wait()
	assert.Equal(t, 4, int(atomic.LoadInt32(&requests)))
}