Skip to content

Commit d7cf75d

Browse files
committed
parsing: fix lint errors
1 parent 9fc3a20 commit d7cf75d

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

pkg/demoinfocs/demoinfocs_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,33 @@ func TestParseToEnd_Cancel(t *testing.T) {
240240
assert.True(t, tix == maxTicks, "FrameDone handler was not triggered the correct amount of times")
241241
}
242242

243+
// See https://github.com/markus-wa/demoinfocs-golang/issues/276
244+
func TestParseToEnd_MultiCancel(t *testing.T) {
245+
t.Parallel()
246+
247+
if testing.Short() {
248+
t.Skip("skipping test")
249+
}
250+
251+
f := openFile(t, defaultDemPath)
252+
defer mustClose(t, f)
253+
254+
p := demoinfocs.NewParser(f)
255+
256+
var handlerID dispatch.HandlerIdentifier
257+
handlerID = p.RegisterEventHandler(func(events.FrameDone) {
258+
p.Cancel()
259+
p.Cancel()
260+
p.Cancel()
261+
p.Cancel()
262+
p.Cancel()
263+
p.UnregisterEventHandler(handlerID)
264+
})
265+
266+
err := p.ParseToEnd()
267+
assert.Equal(t, demoinfocs.ErrCancelled, err, "parsing cancelled but error was not ErrCancelled")
268+
}
269+
243270
func TestInvalidFileType(t *testing.T) {
244271
t.Parallel()
245272

pkg/demoinfocs/parser.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type parser struct {
5959
header *common.DemoHeader // Pointer so we can check for nil
6060
gameState *gameState
6161
demoInfoProvider demoInfoProvider // Provides demo infos to other packages that the core package depends on
62-
cancelChan chan struct{} // Non-anime-related, used for aborting the parsing
62+
cancelled bool // Indicates if Parser.Cancel() has been called
6363
err error // Contains a error that occurred during parsing if any
6464
errLock sync.Mutex // Used to sync up error mutations between parsing & handling go-routines
6565

@@ -303,7 +303,6 @@ func NewParserWithConfig(demostream io.Reader, config ParserConfig) Parser {
303303
p.equipmentMapping = make(map[*st.ServerClass]common.EquipmentType)
304304
p.rawPlayers = make(map[int]*playerInfo)
305305
p.triggers = make(map[int]*boundingBoxInformation)
306-
p.cancelChan = make(chan struct{}, 1)
307306
p.demoInfoProvider = demoInfoProvider{parser: &p}
308307
p.gameState = newGameState(p.demoInfoProvider)
309308
p.grenadeModelIndices = make(map[int]common.EquipmentType)

pkg/demoinfocs/parsing.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func recoverFromUnexpectedEOF(r interface{}) error {
139139
switch err := r.(type) {
140140
case dispatch.ConsumerCodePanic:
141141
panic(err.Value())
142+
142143
default:
143144
panic(err)
144145
}
@@ -203,7 +204,7 @@ const (
203204
dcStringTables demoCommand = 9
204205
)
205206

206-
//nolint:funlen
207+
//nolint:funlen,cyclop
207208
func (p *parser) parseFrame() bool {
208209
cmd := demoCommand(p.bitReader.ReadSingleByte())
209210

@@ -273,6 +274,7 @@ func (p *parser) parseFrame() bool {
273274
var byteSlicePool = sync.Pool{
274275
New: func() interface{} {
275276
s := make([]byte, 0, 256)
277+
276278
return &s
277279
},
278280
}
@@ -338,6 +340,7 @@ func (p *parser) parsePacket() {
338340
}
339341

340342
b := byteSlicePool.Get().(*[]byte)
343+
341344
p.bitReader.ReadBytesInto(b, size)
342345

343346
m := msgCreator()

0 commit comments

Comments
 (0)