mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-04 04:28:08 +00:00 
			
		
		
		
	Moved 'WaitForNodesExcludingSelectedStandbys' to shared testhelpers file (#19976)
This commit is contained in:
		
							
								
								
									
										2
									
								
								.github/workflows/build-vault-oss.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/build-vault-oss.yml
									
									
									
									
										vendored
									
									
								
							@@ -47,7 +47,7 @@ jobs:
 | 
				
			|||||||
      - name: Set up node and yarn
 | 
					      - name: Set up node and yarn
 | 
				
			||||||
        uses: actions/setup-node@v3
 | 
					        uses: actions/setup-node@v3
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          node-version: 14
 | 
					          node-version: 16
 | 
				
			||||||
          cache: yarn
 | 
					          cache: yarn
 | 
				
			||||||
          cache-dependency-path: ui/yarn.lock
 | 
					          cache-dependency-path: ui/yarn.lock
 | 
				
			||||||
      - name: Build UI
 | 
					      - name: Build UI
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1003,3 +1003,34 @@ func SkipUnlessEnvVarsSet(t testing.T, envVars []string) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// WaitForNodesExcludingSelectedStandbys is variation on WaitForActiveNodeAndStandbys.
 | 
				
			||||||
 | 
					// It waits for the active node before waiting for standby nodes, however
 | 
				
			||||||
 | 
					// it will not wait for cores with indexes that match those specified as arguments.
 | 
				
			||||||
 | 
					// Whilst you could specify index 0 which is likely to be the leader node, the function
 | 
				
			||||||
 | 
					// checks for the leader first regardless of the indexes to skip, so it would be redundant to do so.
 | 
				
			||||||
 | 
					// The intention/use case for this function is to allow a cluster to start and become active with one
 | 
				
			||||||
 | 
					// or more nodes not joined, so that we can test scenarios where a node joins later.
 | 
				
			||||||
 | 
					// e.g. 4 nodes in the cluster, only 3 nodes in cluster 'active', 1 node can be joined later in tests.
 | 
				
			||||||
 | 
					func WaitForNodesExcludingSelectedStandbys(t testing.T, cluster *vault.TestCluster, indexesToSkip ...int) {
 | 
				
			||||||
 | 
						WaitForActiveNode(t, cluster)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						contains := func(elems []int, e int) bool {
 | 
				
			||||||
 | 
							for _, v := range elems {
 | 
				
			||||||
 | 
								if v == e {
 | 
				
			||||||
 | 
									return true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for i, core := range cluster.Cores {
 | 
				
			||||||
 | 
							if contains(indexesToSkip, i) {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if standby, _ := core.Core.Standby(); standby {
 | 
				
			||||||
 | 
								WaitForStandbyNode(t, core)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,34 +20,3 @@ func WaitForActiveNodeAndStandbys(t testing.T, cluster *vault.TestCluster) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// WaitForNodesExcludingSelectedStandbys is variation on WaitForActiveNodeAndStandbys.
 | 
					 | 
				
			||||||
// It waits for the active node before waiting for standby nodes, however
 | 
					 | 
				
			||||||
// it will not wait for cores with indexes that match those specified as arguments.
 | 
					 | 
				
			||||||
// Whilst you could specify index 0 which is likely to be the leader node, the function
 | 
					 | 
				
			||||||
// checks for the leader first regardless of the indexes to skip, so it would be redundant to do so.
 | 
					 | 
				
			||||||
// The intention/use case for this function is to allow a cluster to start and become active with one
 | 
					 | 
				
			||||||
// or more nodes not joined, so that we can test scenarios where a node joins later.
 | 
					 | 
				
			||||||
// e.g. 4 nodes in the cluster, only 3 nodes in cluster 'active', 1 node can be joined later in tests.
 | 
					 | 
				
			||||||
func WaitForNodesExcludingSelectedStandbys(t testing.T, cluster *vault.TestCluster, indexesToSkip ...int) {
 | 
					 | 
				
			||||||
	WaitForActiveNode(t, cluster)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	contains := func(elems []int, e int) bool {
 | 
					 | 
				
			||||||
		for _, v := range elems {
 | 
					 | 
				
			||||||
			if v == e {
 | 
					 | 
				
			||||||
				return true
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return false
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for i, core := range cluster.Cores {
 | 
					 | 
				
			||||||
		if contains(indexesToSkip, i) {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if standby, _ := core.Core.Standby(); standby {
 | 
					 | 
				
			||||||
			WaitForStandbyNode(t, core)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user