github.com/matrixorigin/matrixone@v0.7.0/pkg/frontend/routine_manager_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package frontend
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  	"sync"
    21  	"testing"
    22  	"time"
    23  
    24  	"github.com/BurntSushi/toml"
    25  	"github.com/matrixorigin/matrixone/pkg/config"
    26  	"github.com/stretchr/testify/require"
    27  )
    28  
    29  func create_test_server() *MOServer {
    30  	//before anything using the configuration
    31  	pu := config.NewParameterUnit(&config.FrontendParameters{}, nil, nil, nil, nil)
    32  	_, err := toml.DecodeFile("test/system_vars_config.toml", pu.SV)
    33  	if err != nil {
    34  		panic(err)
    35  	}
    36  
    37  	address := fmt.Sprintf("%s:%d", pu.SV.Host, pu.SV.Port)
    38  	moServerCtx := context.WithValue(context.TODO(), config.ParameterUnitKey, pu)
    39  	return NewMOServer(moServerCtx, address, pu)
    40  }
    41  
    42  func Test_Closed(t *testing.T) {
    43  	mo := create_test_server()
    44  	mo.rm.SetSkipCheckUser(true)
    45  	wg := sync.WaitGroup{}
    46  	wg.Add(1)
    47  	cf := &CloseFlag{}
    48  	go func() {
    49  		cf.Open()
    50  		defer wg.Done()
    51  
    52  		err := mo.Start()
    53  		require.NoError(t, err)
    54  
    55  		for cf.IsOpened() {
    56  		}
    57  	}()
    58  
    59  	time.Sleep(100 * time.Millisecond)
    60  	db, err := openDbConn(t, 6001)
    61  	require.NoError(t, err)
    62  	time.Sleep(100 * time.Millisecond)
    63  	closeDbConn(t, db)
    64  	cf.Close()
    65  
    66  	err = mo.Stop()
    67  	require.NoError(t, err)
    68  	wg.Wait()
    69  }