Skip to content

Commit

Permalink
updated for segment id fix if there are no matching segments
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-allen committed Oct 18, 2024
1 parent da09981 commit 8cae4d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/handler/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,15 @@ var EvalFlagWithContext = func(flag *entity.Flag, evalContext models.EvalContext
var vID int64
var sID int64

var evalNextSegment bool

for _, segment := range flag.Segments {
sID = int64(segment.ID)
variantID, log, evalNextSegment := evalSegment(flag.ID, evalContext, segment)
var (
variantID *uint
log *models.SegmentDebugLog
)
variantID, log, evalNextSegment = evalSegment(flag.ID, evalContext, segment)
if config.Config.EvalDebugEnabled && evalContext.EnableDebug {
logs = append(logs, log)
}
Expand All @@ -194,7 +200,9 @@ var EvalFlagWithContext = func(flag *entity.Flag, evalContext models.EvalContext
}
evalResult := BlankResult(flag, evalContext, "")
evalResult.EvalDebugLog.SegmentDebugLogs = logs
evalResult.SegmentID = sID
if !evalNextSegment {
evalResult.SegmentID = sID
}
evalResult.VariantID = vID
v := flag.FlagEvaluation.VariantsMap[util.SafeUint(vID)]
if v != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/handler/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func TestEvalFlag(t *testing.T) {
FlagID: int64(100),
})
assert.NotNil(t, result)
assert.Equal(t, result.SegmentID, int64(200))
assert.NotZero(t, result.VariantID)
})

Expand Down Expand Up @@ -300,6 +301,7 @@ func TestEvalFlag(t *testing.T) {
FlagID: int64(100),
})
assert.NotNil(t, result)
assert.Equal(t, result.SegmentID, int64(0))
assert.Zero(t, result.VariantID)
})

Expand Down

0 comments on commit 8cae4d1

Please sign in to comment.