github.com/matrixorigin/matrixone@v1.2.0/pkg/frontend/migrate_test.go (about)

     1  // Copyright 2021 - 2024 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  	"testing"
    19  	"time"
    20  
    21  	"github.com/stretchr/testify/assert"
    22  )
    23  
    24  func TestNewMigrateController(t *testing.T) {
    25  	mc := newMigrateController()
    26  	assert.NotNil(t, mc)
    27  }
    28  
    29  func TestCloseOnly(t *testing.T) {
    30  	mc := newMigrateController()
    31  	assert.NotNil(t, mc)
    32  	mc.waitAndClose()
    33  }
    34  
    35  func TestFirstCloseThenMigrate(t *testing.T) {
    36  	mc := newMigrateController()
    37  	assert.NotNil(t, mc)
    38  	mc.waitAndClose()
    39  	assert.Equal(t, mc.beginMigrate(), false)
    40  }
    41  
    42  func TestFirstMigrateThenClose(t *testing.T) {
    43  	mc := newMigrateController()
    44  	assert.NotNil(t, mc)
    45  	assert.Equal(t, mc.beginMigrate(), true)
    46  	mc.endMigrate()
    47  	mc.waitAndClose()
    48  }
    49  
    50  func TestCloseWaitMigrate(t *testing.T) {
    51  	mc := newMigrateController()
    52  	assert.NotNil(t, mc)
    53  	assert.Equal(t, mc.beginMigrate(), true)
    54  	go func() {
    55  		<-time.After(time.Second)
    56  		mc.endMigrate()
    57  	}()
    58  	mc.waitAndClose()
    59  }