Explorar el Código

Fix Burndown serialization errors

Vadim Markovtsev hace 7 años
padre
commit
cafd320bc2
Se han modificado 3 ficheros con 13 adiciones y 2 borrados
  1. 6 2
      burndown.go
  2. 4 0
      burndown_test.go
  3. 3 0
      pb/utils.go

+ 6 - 2
burndown.go

@@ -698,7 +698,9 @@ func (analyser *BurndownAnalysis) serializeBinary(result *BurndownResult, writer
 	message := pb.BurndownAnalysisResults{
 		Granularity: int32(analyser.Granularity),
 		Sampling:    int32(analyser.Sampling),
-		Project:     pb.ToBurndownSparseMatrix(result.GlobalHistory, "project"),
+	}
+	if len(result.GlobalHistory) > 0 {
+		message.Project = pb.ToBurndownSparseMatrix(result.GlobalHistory, "project")
 	}
 	if len(result.FileHistories) > 0 {
 		message.Files = make([]*pb.BurndownSparseMatrix, len(result.FileHistories))
@@ -715,7 +717,9 @@ func (analyser *BurndownAnalysis) serializeBinary(result *BurndownResult, writer
 		message.People = make(
 			[]*pb.BurndownSparseMatrix, len(result.PeopleHistories))
 		for key, val := range result.PeopleHistories {
-			message.People[key] = pb.ToBurndownSparseMatrix(val, result.reversedPeopleDict[key])
+			if len(val) > 0 {
+				message.People[key] = pb.ToBurndownSparseMatrix(val, result.reversedPeopleDict[key])
+			}
 		}
 		message.PeopleInteraction = pb.DenseToCompressedSparseRowMatrix(result.PeopleMatrix)
 	}

+ 4 - 0
burndown_test.go

@@ -3,6 +3,7 @@ package hercules
 import (
 	"bytes"
 	"io"
+	"io/ioutil"
 	"testing"
 
 	"github.com/gogo/protobuf/proto"
@@ -848,6 +849,7 @@ func TestBurndownMergeGlobalHistory(t *testing.T) {
 	assert.Equal(t, merged.PeopleMatrix[2][2], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][3], int64(700))
 	assert.Equal(t, merged.PeopleMatrix[2][4], int64(800))
+	burndown.serializeBinary(&merged, ioutil.Discard)
 }
 
 func TestBurndownMergeNils(t *testing.T) {
@@ -889,6 +891,7 @@ func TestBurndownMergeNils(t *testing.T) {
 	assert.Nil(t, merged.FileHistories)
 	assert.Nil(t, merged.PeopleHistories)
 	assert.Nil(t, merged.PeopleMatrix)
+	burndown.serializeBinary(&merged, ioutil.Discard)
 
 	res2.GlobalHistory = make([][]int64, 56/14 /* 4 samples */)
 	for i := range res2.GlobalHistory {
@@ -957,4 +960,5 @@ func TestBurndownMergeNils(t *testing.T) {
 	assert.Equal(t, merged.PeopleMatrix[2][2], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][3], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][4], int64(0))
+	burndown.serializeBinary(&merged, ioutil.Discard)
 }

+ 3 - 0
pb/utils.go

@@ -3,6 +3,9 @@ package pb
 import "sort"
 
 func ToBurndownSparseMatrix(matrix [][]int64, name string) *BurndownSparseMatrix {
+	if len(matrix) == 0 {
+		panic("matrix may not be nil or empty")
+	}
 	r := BurndownSparseMatrix{
 		Name:            name,
 		NumberOfRows:    int32(len(matrix)),