You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.3 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  9. )
  10. func TestGenerator(t *testing.T) {
  11. manifests, err := Generate(rand.New(rand.NewSource(randomSeed)), Options{P2P: MixedP2PMode})
  12. require.NoError(t, err)
  13. require.True(t, len(manifests) >= 64, "insufficient combinations")
  14. // this just means that the numbers reported by the test
  15. // failures map to the test cases that you'd see locally.
  16. e2e.SortManifests(manifests, false /* ascending */)
  17. for idx, m := range manifests {
  18. t.Run(fmt.Sprintf("Case%04d", idx), func(t *testing.T) {
  19. numStateSyncs := 0
  20. for name, node := range m.Nodes {
  21. if node.StateSync != e2e.StateSyncDisabled {
  22. numStateSyncs++
  23. }
  24. t.Run(name, func(t *testing.T) {
  25. if node.StartAt > m.InitialHeight+5 && !node.Stateless() {
  26. require.NotEqual(t, node.StateSync, e2e.StateSyncDisabled)
  27. }
  28. if node.StateSync != e2e.StateSyncDisabled {
  29. require.Zero(t, node.Seeds, node.StateSync)
  30. require.True(t, len(node.PersistentPeers) >= 2)
  31. require.Equal(t, "v0", node.BlockSync)
  32. }
  33. })
  34. }
  35. require.True(t, numStateSyncs <= 2)
  36. })
  37. }
  38. t.Run("Hybrid", func(t *testing.T) {
  39. manifests, err := Generate(rand.New(rand.NewSource(randomSeed)), Options{P2P: HybridP2PMode})
  40. require.NoError(t, err)
  41. require.True(t, len(manifests) >= 16, "insufficient combinations: %d", len(manifests))
  42. // failures map to the test cases that you'd see locally.
  43. e2e.SortManifests(manifests, false /* ascending */)
  44. for idx, m := range manifests {
  45. t.Run(fmt.Sprintf("Case%04d", idx), func(t *testing.T) {
  46. require.True(t, len(m.Nodes) > 1)
  47. var numLegacy, numNew int
  48. for _, node := range m.Nodes {
  49. if node.UseLegacyP2P {
  50. numLegacy++
  51. } else {
  52. numNew++
  53. }
  54. }
  55. assert.True(t, numLegacy >= 1, "not enough legacy nodes [%d/%d]",
  56. numLegacy, len(m.Nodes))
  57. assert.True(t, numNew >= 1, "not enough new nodes [%d/%d]",
  58. numNew, len(m.Nodes))
  59. })
  60. }
  61. })
  62. t.Run("UnmixedP2P", func(t *testing.T) {
  63. t.Run("New", func(t *testing.T) {
  64. manifests, err := Generate(rand.New(rand.NewSource(randomSeed)), Options{P2P: NewP2PMode})
  65. require.NoError(t, err)
  66. require.True(t, len(manifests) >= 16, "insufficient combinations: %d", len(manifests))
  67. // failures map to the test cases that you'd see locally.
  68. e2e.SortManifests(manifests, false /* ascending */)
  69. for idx, m := range manifests {
  70. t.Run(fmt.Sprintf("Case%04d", idx), func(t *testing.T) {
  71. for name, node := range m.Nodes {
  72. t.Run(name, func(t *testing.T) {
  73. require.False(t, node.UseLegacyP2P)
  74. })
  75. }
  76. })
  77. }
  78. })
  79. t.Run("Legacy", func(t *testing.T) {
  80. manifests, err := Generate(rand.New(rand.NewSource(randomSeed)), Options{P2P: LegacyP2PMode})
  81. require.NoError(t, err)
  82. require.True(t, len(manifests) >= 16, "insufficient combinations: %d", len(manifests))
  83. // failures map to the test cases that you'd see locally.
  84. e2e.SortManifests(manifests, false /* ascending */)
  85. for idx, m := range manifests {
  86. t.Run(fmt.Sprintf("Case%04d", idx), func(t *testing.T) {
  87. for name, node := range m.Nodes {
  88. t.Run(name, func(t *testing.T) {
  89. require.True(t, node.UseLegacyP2P)
  90. })
  91. }
  92. })
  93. }
  94. })
  95. })
  96. }