Skip to content

Commit

Permalink
test: add a test for DiffV1.
Browse files Browse the repository at this point in the history
This will currently fail due to
#812 and
#820
  • Loading branch information
abeaumont committed Feb 10, 2022
1 parent b4aa45c commit f7ca4a2
Showing 1 changed file with 74 additions and 6 deletions.
80 changes: 74 additions & 6 deletions pkg/adhoc/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pyroscope-io/pyroscope/pkg/adhoc/server"
"github.com/pyroscope-io/pyroscope/pkg/structs/flamebearer"
)

var _ = Describe("Server", func() {
Expand Down Expand Up @@ -518,14 +519,81 @@ var _ = Describe("Server", func() {
})
})
})
})

Context("with an empty model", func() {
var m server.Model
It("should return an error", func() {
_, err := m.Converter()
Expect(err).ToNot(Succeed())
Context("with an empty model", func() {
var m server.Model
It("should return an error", func() {
_, err := m.Converter()
Expect(err).ToNot(Succeed())
})
})
})

Describe("Calling DiffV1", func() {
Context("with v1 profiles", func() {
var base, diff *flamebearer.FlamebearerProfile

When("Diff is called with valid and equal base and diff profiles", func() {
BeforeEach(func() {

base = &flamebearer.FlamebearerProfile{
Version: 1,
FlamebearerProfileV1: flamebearer.FlamebearerProfileV1{
Metadata: flamebearer.FlamebearerMetadataV1{
Format: "single",
},
// Taken from flamebearer test
Flamebearer: flamebearer.FlamebearerV1{
Names: []string{"total", "a", "b", "c"},
Levels: [][]int{
{0, 3, 0, 0},
{0, 3, 0, 1},
{0, 1, 1, 3, 0, 2, 2, 2},
},
NumTicks: 3,
MaxSelf: 2,
},
},
}

diff = &flamebearer.FlamebearerProfile{
Version: 1,
FlamebearerProfileV1: flamebearer.FlamebearerProfileV1{
Metadata: flamebearer.FlamebearerMetadataV1{
Format: "single",
},
// Taken from flamebearer test
Flamebearer: flamebearer.FlamebearerV1{
Names: []string{"total", "a", "b", "c"},
Levels: [][]int{
{0, 3, 0, 0},
{0, 3, 0, 1},
{0, 1, 1, 3, 0, 2, 2, 2},
},
NumTicks: 3,
MaxSelf: 2,
},
},
}
})

It("returns the diff profile", func() {
fb, err := server.DiffV1(base, diff, 1024)
Expect(err).To(Succeed())
Expect(fb.Version).To(Equal(uint(1)))
Expect(fb.Metadata.Format).To(Equal("double"))
Expect(fb.Flamebearer.Names).To(ConsistOf("total", "a", "b", "c"))
Expect(fb.Flamebearer.Levels).To(Equal([][]int{
{0, 3, 0, 0, 3, 0, 0},
{0, 3, 0, 0, 3, 0, 1},
{0, 1, 1, 0, 1, 1, 3, 0, 2, 2, 0, 2, 2, 2},
}))
Expect(fb.Flamebearer.NumTicks).To(Equal(3))
Expect(fb.Flamebearer.MaxSelf).To(Equal(2))
Expect(fb.LeftTicks).To(Equal(3))
Expect(fb.RightTicks).To(Equal(3))
})
})
})
})
})

0 comments on commit f7ca4a2

Please sign in to comment.