MCPcopy
hub / github.com/grafana/tempo / TestEdgeCases

Function TestEdgeCases

modules/backendscheduler/work/work_sharded_test.go:554–597  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

552}
553
554func TestEdgeCases(t *testing.T) {
555 work := New(Config{})
556
557 t.Run("operations on nonexistent jobs", func(t *testing.T) {
558 // These should not panic
559 work.StartJob("nonexistent")
560 work.CompleteJob("nonexistent")
561 work.FailJob("nonexistent")
562 work.SetJobCompactionOutput("nonexistent", []string{"output"})
563 work.RemoveJob("nonexistent")
564
565 job := work.GetJob("nonexistent")
566 require.Nil(t, job)
567 })
568
569 t.Run("empty work operations", func(t *testing.T) {
570 emptyWork := New(Config{})
571
572 require.Equal(t, 0, len(emptyWork.ListJobs()))
573 require.Empty(t, emptyWork.ListJobs())
574
575 ctx := context.Background()
576 foundJob := emptyWork.GetJobForWorker(ctx, "any-worker")
577 require.Nil(t, foundJob)
578
579 // Prune should not panic on empty work
580 emptyWork.Prune(ctx)
581
582 // Marshal/unmarshal empty work
583 data, err := emptyWork.Marshal()
584 require.NoError(t, err)
585
586 newWork := New(Config{})
587 err = newWork.Unmarshal(data)
588 require.NoError(t, err)
589 require.Equal(t, 0, len(newWork.ListJobs()))
590 })
591
592 t.Run("unmarshal invalid data", func(t *testing.T) {
593 newWork := New(Config{})
594 err := newWork.Unmarshal([]byte("invalid json"))
595 require.Error(t, err)
596 })
597}
598
599// TestFullMarshalUnmarshal tests the full work cache serialization across all shards
600func TestFullMarshalUnmarshal(t *testing.T) {

Callers

nothing calls this directly

Calls 15

NewFunction · 0.70
StartJobMethod · 0.65
CompleteJobMethod · 0.65
FailJobMethod · 0.65
RemoveJobMethod · 0.65
GetJobMethod · 0.65
ListJobsMethod · 0.65
GetJobForWorkerMethod · 0.65
PruneMethod · 0.65
MarshalMethod · 0.65
UnmarshalMethod · 0.65

Tested by

no test coverage detected