Atlas › Test

TestBufferApplyAfterCancel

Exact test identity: go.temporal.io/server/common/effect/TestBufferApplyAfterCancel

Package
go.temporal.io/server/common/effect
Suite / test hierarchy
TestBufferApplyAfterCancel
Test
TestBufferApplyAfterCancel
Introduced at
TestBufferApplyAfterCancel Frontier kind: Test frontier
Covered ranges
7
Covered lines
21
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/effect/buffer.go 21 covered LOC · 7 ranges

Open complete file

14 // OnAfterCommit adds the provided effect function to set of such functions to
15 // be invoked when Buffer.Apply is called.
16 > func (b *Buffer) OnAfterCommit(effect func(context.Context)) { buffer.go
17 > b.effects = append(b.effects, effect)
18 > }
19
20 // OnAfterRollback adds the provided effect function to set of such functions to
21 // be invoked when Buffer.Cancel is called.
22 > func (b *Buffer) OnAfterRollback(effect func(context.Context)) { buffer.go
23 > b.cancels = append(b.cancels, effect)
24 > }
25
26 // Apply invokes the buffered effect functions in the order that they were added
27 // to this Buffer.
28 // It returns true if any effects were applied.
29 > func (b *Buffer) Apply(ctx context.Context) bool { buffer.go
30 > applied := false
31 > b.cancels = nil
32 > for _, effect := range b.effects {
33 effect(ctx)
34 applied = true
35 }
36 > b.effects = nil buffer.go
37 > return applied
38 }
39
41 // that they were added to this Buffer.
42 // It returns true if any effects were canceled.
43 > func (b *Buffer) Cancel(ctx context.Context) bool { buffer.go
44 > canceled := false
45 > b.effects = nil
46 > for i := len(b.cancels) - 1; i >= 0; i-- {
47 > b.cancels[i](ctx) buffer.go
48 > canceled = true
49 > }
50 > b.cancels = nil buffer.go
51 > return canceled
52 }