Skip to content

Commit

Permalink
reconciler: Implement tests using scripttest
Browse files Browse the repository at this point in the history
Reimplement the reconciler tests using scripttest. This significantly
simplifies the test-suite and allows easier verification of more complex
scenarios.

To allow for Status JSON and YAML marshalling, define custom UnmarshalJSON
and UnmarshalYAML that also fill in the 'id'. The 'id' is used with StatusSet
to efficiently allow multiple reconcilers to manipulate the status without
conflicts, e.g. if the object status id is the same it can still be updated
with the reconciliation result even if the object conflicted due to other
reconciler's update to its status.

Signed-off-by: Jussi Maki <jussi.maki@isovalent.com>
  • Loading branch information
joamaki committed Oct 9, 2024
1 parent f0f878c commit 950e499
Show file tree
Hide file tree
Showing 10 changed files with 833 additions and 679 deletions.
12 changes: 11 additions & 1 deletion reconciler/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
)

type ExpVarMetrics struct {
root *expvar.Map

ReconciliationCountVar *expvar.Map
ReconciliationDurationVar *expvar.Map
ReconciliationTotalErrorsVar *expvar.Map
Expand Down Expand Up @@ -73,14 +75,22 @@ func NewUnpublishedExpVarMetrics() *ExpVarMetrics {
return newExpVarMetrics(false)
}

func (m *ExpVarMetrics) Map() *expvar.Map {
return m.root
}

func newExpVarMetrics(publish bool) *ExpVarMetrics {
root := new(expvar.Map).Init()
newMap := func(name string) *expvar.Map {
if publish {
return expvar.NewMap(name)
}
return new(expvar.Map).Init()
m := new(expvar.Map).Init()
root.Set(name, m)
return m
}
return &ExpVarMetrics{
root: root,
ReconciliationCountVar: newMap("reconciliation_count"),
ReconciliationDurationVar: newMap("reconciliation_duration"),
ReconciliationTotalErrorsVar: newMap("reconciliation_total_errors"),
Expand Down
5 changes: 5 additions & 0 deletions reconciler/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func TestMultipleReconcilers(t *testing.T) {
cell.Provide(
cell.NewSimpleHealth,
reconciler.NewExpVarMetrics,
func(r job.Registry, h cell.Health, lc cell.Lifecycle) job.Group {
g := r.NewGroup(h)
lc.Append(g)
return g
},
),
cell.Invoke(func(db_ *statedb.DB) error {
db = db_
Expand Down
Loading

0 comments on commit 950e499

Please sign in to comment.