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: txn_external_test.go
    path of file: ./repos/cockroach/pkg/kv
    
    the code of the file until where you have to start completion: // Copyright 2020 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 kv_test

import (
	"context"
	"math/rand"
	"sync/atomic"
	"testing"
	"time"

	"github.com/cockroachdb/cockroach/pkg/base"
	"github.com/cockroachdb/cockroach/pkg/kv"
	"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
	"github.com/cockroachdb/cockroach/pkg/kv/kvserver"
	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/isolation"
	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock"
	"github.com/cockroachdb/cockroach/pkg/roachpb"
	"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
	"github.com/cockroachdb/cockroach/pkg/testutils"
	"github.com/cockroachdb/cockroach/pkg/testutils/kvclientutils"
	"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
	"github.com/cockroachdb/cockroach/pkg/testutils/skip"
	"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
	"github.com/cockroac
    
func testGenerateForcedRetryableErrorByPoisoning(t *testing.T, isoLevel isolation.Level) {
	ctx := context.Background()
	ts, _, db := serverutils.StartServer(t, base.TestServerArgs{})
	defer ts.Stopper().Stop(ctx)
	k, err := ts.ScratchRange()
	require.NoError(t, err)
	mkKey := func(s string) roachpb.Key {
		return encoding.EncodeStringAscending(k[:len(k):len(k)], s)
	}
	checkKey := func(t *testing.T, s string, exp int64) {
		got, err := db.Get(ctx, mkKey(s))
		require.NoError(t, err)
		require.Equal(t, exp, got.ValueInt())
	}
	var i int
	require.NoError(t, db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
		require.NoError(t, txn.SetIsoLevel(isoLevel))
		{
			// Verify 'a' is not written yet.
			got, err := txn.Get(ctx, mkKey("a"))
			require.NoError(t, err, got.ValueInt())
			require.False(t, got.Exists(), got.ValueInt())
		}
		require.NoError(t, txn.Put(ctx, mkKey("a"), 1))
		// Retry exactly once by propagating a retry error.
		if i++; i == 1 {
			// Generate an error and then return nil (not the ideal implementation but
			// should work).
			_ = txn.GenerateForcedRetryableErr(ctx, "force retry")
			return nil
		}
		require.NoError(t, txn.Put(ctx, mkKey("b"), 2))
		return nil
	}))
	checkKey(t, "a", 1)
	checkKey(t, "b", 2)
}