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: kv_writer_test.go
    path of file: ./repos/cockroach/pkg/sql/catalog/lease
    
    the code of the file until where you have to start completion: // Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package lease

import (
	"context"
	"fmt"
	"math/rand"
	"strings"
	"testing"
	"time"

	"github.com/cockroachdb/cockroach/pkg/base"
	"github.com/cockroachdb/cockroach/pkg/keys"
	"github.com/cockroachdb/cockroach/pkg/kv"
	"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
	"github.com/cockroachdb/cockroach/pkg/roachpb"
	"github.com/cockroachdb/cockroach/pkg/server/settingswatcher"
	"github.com/cockroachdb/cockroach/pkg/settings/cluster"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema"
	"github.com/cockroachdb/cockroach/pkg/sql/enum"
	"github.com/cockroachdb/cockroach/pkg/sql/isql"
	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
	kvstorage "github.com/cockroachdb/cockroach/pkg/storage"
	"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
	"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
	"github.com/cockroachdb/cockroach/pkg/util/hlc"
	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
	"github.com/cockroachdb/cockroach/pkg/util/log"
	"github
    
func TestKVWriterMatchesIEWriter(t *testing.T) {
	defer leaktest.AfterTest(t)()
	defer log.Scope(t).Close(t)

	for _, mode := range []SessionBasedLeasingMode{SessionBasedLeasingOff, SessionBasedOnly} {
		t.Run(fmt.Sprintf("mode=%s", mode.String()), func(t *testing.T) {
			ctx := context.Background()
			serverArgs := base.TestServerArgs{}
			serverArgs.Settings = cluster.MakeClusterSettings()
			srv, sqlDB, kvDB := serverutils.StartServer(t, serverArgs)
			defer srv.Stopper().Stop(ctx)
			s := srv.ApplicationLayer()
			LeaseEnableSessionBasedLeasing.Override(ctx, &s.ClusterSettings().SV, int64(mode))

			// Otherwise, we wouldn't get complete SSTs in our export under stress.
			sqlutils.MakeSQLRunner(srv.SystemLayer().SQLConn(t)).Exec(
				t, "SET CLUSTER SETTING admission.elastic_cpu.enabled = false",
			)

			tdb := sqlutils.MakeSQLRunner(sqlDB)
			schema := systemschema.LeaseTableSchema
			if mode == SessionBasedOnly {
				schema = systemschema.LeaseTableSchema_V24_1
			}
			makeTable := func(name string) (id descpb.ID) {
				tdb.Exec(t, strings.Replace(schema, "system.lease", name, 1))
				tdb.QueryRow(t, "SELECT id FROM system.namespace WHERE name = $1", name).Scan(&id)
				// Modifies the primary index IDs to line up with the session based
				// or multi-region expiry based formats of the table.
				if mode == SessionBasedOnly {
					MoveTablePrimaryIndexIDtoTarget(ctx, t, s, id, 3)
				} else {
					MoveTablePrimaryIndexIDtoTarget(ctx, t, s, id, 2)
				}
				return id
			}
			lease1ID := makeTable("lease1")
			lease2ID := makeTable("lease2")

			ie := s.InternalExecutor().(isql.Executor)
			codec := s.Codec()
			settingsWatcher := s.SettingsWatcher().(*settingswatcher.SettingsWatcher)
			modeReader := &dummySessionModeReader{mode: mode}
			w := teeWriter{
				a: newInternalExecutorWriter(ie, "defaultdb.public.lease1", mode),
				b: newKVWriter(codec, kvDB, lease2ID, settingsWatcher, modeReader),
			}
			start := kvDB.Clock().Now()
			groups := generateWriteOps(2<<10, 1<<10)
			for {
				ops, ok := groups()
				if !ok {
					break
				}
				do := func(i int, txn *kv.Txn) error {
					return ops[i].f(w, ctx, txn, ops[i].leaseFields)
				}
				if len(ops) == 1 {
					require.NoError(t, do(0, nil /* txn */))
				} else {
					require.NoError(t, kvDB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
						for i := range ops {
							if err := do(i, txn); err != nil {
								return err
							}
						}
						return nil
					}))
				}
			}
			require.Equal(
				t,
				getRawHistoryKVs(ctx, t, kvDB, lease1ID, start, codec),
				getRawHistoryKVs(ctx, t, kvDB, lease2ID, start, codec),
			)
		})
	}
}