github.com/matrixorigin/matrixone@v1.2.0/pkg/util/debug/goroutine/parser_test.go (about) 1 // Copyright 2023 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 goroutine 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 "github.com/stretchr/testify/require" 22 ) 23 24 func TestParseGoroutineLine(t *testing.T) { 25 cases := []struct { 26 line string 27 expect Goroutine 28 }{ 29 { 30 line: "goroutine 628 [IO wait, 8 minutes]:", 31 expect: Goroutine{ 32 ID: 628, 33 State: "IO wait", 34 BlockedMinutes: 8, 35 rawState: "goroutine 628 [IO wait, 8 minutes]:", 36 }, 37 }, 38 { 39 line: "goroutine 628 [runnable]:", 40 expect: Goroutine{ 41 ID: 628, 42 State: "runnable", 43 rawState: "goroutine 628 [runnable]:", 44 }, 45 }, 46 } 47 48 for _, c := range cases { 49 g := Goroutine{} 50 readGoroutineLine(c.line, &g) 51 assert.Equal(t, c.expect, g) 52 } 53 } 54 55 func TestParse(t *testing.T) { 56 stacks := `goroutine 99 [select]: 57 github.com/panjf2000/ants/v2.(*Pool).purgeStaleWorkers(0xc000504000, {0x36add70, 0xc0007b5f90}) 58 /home/go/pkg/mod/github.com/panjf2000/ants/v2@v2.7.4/pool.go:83 +0x10a 59 created by github.com/panjf2000/ants/v2.(*Pool).goPurge 60 /home/go/pkg/mod/github.com/panjf2000/ants/v2@v2.7.4/pool.go:148 +0xe5 61 62 goroutine 100 [select]: 63 github.com/panjf2000/ants/v2.(*Pool).ticktock(0xc000504000, {0x36add70, 0xc000054140}) 64 /home/go/pkg/mod/github.com/panjf2000/ants/v2@v2.7.4/pool.go:126 +0x145 65 created by github.com/panjf2000/ants/v2.(*Pool).goTicktock 66 /home/go/pkg/mod/github.com/panjf2000/ants/v2@v2.7.4/pool.go:155 +0x115 67 ` 68 gs := parse([]byte(stacks)) 69 require.Equal(t, 2, len(gs)) 70 }