github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/builtins/generator_builtins_test.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package builtins
    12  
    13  import (
    14  	"context"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/base"
    18  	"github.com/cockroachdb/cockroach/pkg/kv"
    19  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    20  	"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
    21  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestConcurrentProcessorsReadEpoch(t *testing.T) {
    26  	defer leaktest.AfterTest(t)()
    27  	ctx := context.Background()
    28  	params := base.TestServerArgs{
    29  		Knobs: base.TestingKnobs{
    30  			SQLEvalContext: &tree.EvalContextTestingKnobs{
    31  				CallbackGenerators: map[string]*tree.CallbackValueGenerator{
    32  					"my_callback": tree.NewCallbackValueGenerator(
    33  						func(ctx context.Context, prev int, _ *kv.Txn) (int, error) {
    34  							if prev < 10 {
    35  								return prev + 1, nil
    36  							}
    37  							return -1, nil
    38  						}),
    39  				},
    40  			},
    41  		},
    42  	}
    43  	s, db, _ := serverutils.StartServer(t, params)
    44  	defer s.Stopper().Stop(ctx)
    45  
    46  	rows, err := db.Query(` select * from crdb_internal.testing_callback('my_callback')`)
    47  	require.NoError(t, err)
    48  	exp := 1
    49  	for rows.Next() {
    50  		var got int
    51  		require.NoError(t, rows.Scan(&got))
    52  		require.Equal(t, exp, got)
    53  		exp++
    54  	}
    55  }