github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/gc/gc_test.go (about) 1 // Copyright 2021 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 gc 16 17 import ( 18 "context" 19 "sync/atomic" 20 "testing" 21 "time" 22 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils" 24 "github.com/stretchr/testify/assert" 25 ) 26 27 func noopTestJob(_ context.Context) (err error) { return } 28 29 func TestManager(t *testing.T) { 30 assert.Panics( 31 t, 32 func() { 33 _ = NewManager( 34 WithCronJob("n1", time.Second, noopTestJob), 35 WithCronJob("n1", time.Second, noopTestJob), 36 ) 37 }, 38 ) 39 40 var ints []int 41 var cnt atomic.Int32 42 mgr := NewManager( 43 WithCronJob("n2", 3*time.Millisecond, func(_ context.Context) (err error) { 44 ints = append(ints, 2) 45 cnt.Add(1) 46 return 47 }), 48 WithCronJob("n1", 5*time.Millisecond, func(_ context.Context) (err error) { 49 ints = append(ints, 1) 50 cnt.Add(1) 51 return 52 }), 53 ) 54 55 mgr.Start() 56 testutils.WaitExpect(1000, func() bool { 57 return cnt.Load() >= int32(2) 58 }) 59 time.Sleep(20 * time.Millisecond) 60 mgr.Stop() 61 t.Log(ints) 62 assert.Equal(t, []int{2, 1}, ints[0:2]) 63 }