We were ignoring quite a few error cases, and had one case where we weren't actually updating state where we wanted to. Unfortunately, if the linter doesn't pass, nobody has any reason to actually check lint failures in CI. There are three remaining XXXs marked in the code for lint.
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package stats
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/filecoin-project/lotus/api"
 | |
| 	"github.com/stretchr/testify/require"
 | |
| )
 | |
| 
 | |
| func TestHeadBuffer(t *testing.T) {
 | |
| 
 | |
| 	t.Run("Straight push through", func(t *testing.T) {
 | |
| 		hb := newHeadBuffer(5)
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "1"}))
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "2"}))
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "3"}))
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "4"}))
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "5"}))
 | |
| 
 | |
| 		hc := hb.push(&api.HeadChange{Type: "6"})
 | |
| 		require.Equal(t, hc.Type, "1")
 | |
| 	})
 | |
| 
 | |
| 	t.Run("Reverts", func(t *testing.T) {
 | |
| 		hb := newHeadBuffer(5)
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "1"}))
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "2"}))
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "3"}))
 | |
| 		hb.pop()
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "3a"}))
 | |
| 		hb.pop()
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "3b"}))
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "4"}))
 | |
| 		require.Nil(t, hb.push(&api.HeadChange{Type: "5"}))
 | |
| 
 | |
| 		hc := hb.push(&api.HeadChange{Type: "6"})
 | |
| 		require.Equal(t, hc.Type, "1")
 | |
| 		hc = hb.push(&api.HeadChange{Type: "7"})
 | |
| 		require.Equal(t, hc.Type, "2")
 | |
| 		hc = hb.push(&api.HeadChange{Type: "8"})
 | |
| 		require.Equal(t, hc.Type, "3b")
 | |
| 	})
 | |
| }
 |