-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added iterator API over query phases
- Loading branch information
1 parent
0d3f84a
commit 7347733
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build go1.23 | ||
|
||
package stats | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_TableStats" | ||
) | ||
|
||
func TestIterateOverQueryPhases(t *testing.T) { | ||
s := &QueryStats{ | ||
pb: &Ydb_TableStats.QueryStats{ | ||
QueryPhases: []*Ydb_TableStats.QueryPhaseStats{ | ||
{ | ||
DurationUs: 1, | ||
}, | ||
{ | ||
DurationUs: 2, | ||
}, | ||
{ | ||
DurationUs: 3, | ||
}, | ||
}, | ||
}, | ||
} | ||
t.Run("ImmutableIteration", func(t *testing.T) { | ||
for i := range make([]struct{}, 3) { | ||
t.Run(fmt.Sprintf("Pass#%d", i), func(t *testing.T) { | ||
durations := make([]uint64, 0, 3) | ||
for phase := range s.QueryPhases() { | ||
durations = append(durations, phase.pb.GetDurationUs()) | ||
} | ||
require.Equal(t, []uint64{1, 2, 3}, durations) | ||
}) | ||
} | ||
}) | ||
t.Run("MutableIteration", func(t *testing.T) { | ||
durations := make([]uint64, 0, 3) | ||
for { | ||
phase, ok := s.NextPhase() | ||
if !ok { | ||
break | ||
} | ||
durations = append(durations, phase.pb.GetDurationUs()) | ||
} | ||
require.Equal(t, []uint64{1, 2, 3}, durations) | ||
require.Equal(t, 3, s.pos) | ||
|
||
_, ok := s.NextPhase() | ||
require.False(t, ok) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters