vitess.io/vitess@v0.16.2/go/test/endtoend/stress/stress_test.go (about)

     1  /*
     2  Copyright 2021 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package stress
    18  
    19  import (
    20  	"flag"
    21  	"os"
    22  	"testing"
    23  
    24  	"vitess.io/vitess/go/test/stress"
    25  
    26  	"vitess.io/vitess/go/mysql"
    27  	"vitess.io/vitess/go/test/endtoend/cluster"
    28  )
    29  
    30  var (
    31  	clusterInstance *cluster.LocalProcessCluster
    32  	vtParams        mysql.ConnParams
    33  	keyspaceName    = "ks"
    34  	cell            = "zone1"
    35  	sqlSchema       = `
    36  		create table main (
    37  			id bigint,
    38  			val varchar(128),
    39  			primary key(id)
    40  		) Engine=InnoDB;
    41  `
    42  )
    43  
    44  func TestMain(m *testing.M) {
    45  	defer cluster.PanicHandler(nil)
    46  	flag.Parse()
    47  
    48  	exitCode := func() int {
    49  		clusterInstance = cluster.NewCluster(cell, "localhost")
    50  		defer clusterInstance.Teardown()
    51  
    52  		// Start topo server
    53  		err := clusterInstance.StartTopo()
    54  		if err != nil {
    55  			return 1
    56  		}
    57  
    58  		// Start keyspace
    59  		keyspace := &cluster.Keyspace{
    60  			Name:      keyspaceName,
    61  			SchemaSQL: sqlSchema,
    62  		}
    63  		err = clusterInstance.StartUnshardedKeyspace(*keyspace, 0, false)
    64  		if err != nil {
    65  			return 1
    66  		}
    67  
    68  		// Start vtgate
    69  		err = clusterInstance.StartVtgate()
    70  		if err != nil {
    71  			return 1
    72  		}
    73  
    74  		vtParams = mysql.ConnParams{
    75  			Host: clusterInstance.Hostname,
    76  			Port: clusterInstance.VtgateMySQLPort,
    77  		}
    78  		return m.Run()
    79  	}()
    80  	os.Exit(exitCode)
    81  }
    82  
    83  // This test portrays an end-to-end test that runs on a loaded cluster.
    84  // The stressor is started on its own goroutine while the end-to-end test
    85  // is executed on the same cluster.
    86  func TestSimpleStressTest(t *testing.T) {
    87  	defer cluster.PanicHandler(t)
    88  
    89  	cfg := stress.DefaultConfig
    90  	cfg.ConnParams = &vtParams
    91  	s := stress.New(t, cfg)
    92  
    93  	s.Start()
    94  
    95  	// Vitess end-to-end test here
    96  
    97  	s.Stop()
    98  }