/* SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ /* * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. * * Licensed to Elasticsearch B.V. under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch B.V. licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ using System; using OpenSearch.Stack.ArtifactsApi; namespace Tests.Configuration { public abstract class TestConfigurationBase { /// If specified will only run integration test against these comma separated clusters public string ClusterFilter { get; protected set; } /// comma separated list of test method names to execute public string TestFilter { get; protected set; } /// The OpenSearch version to test against, defined for both unit and integration tests public OpenSearchVersion OpenSearchVersion { get; protected set; } /// Force a reseed (bootstrap) of the cluster even if checks indicate bootstrap already ran public bool ForceReseed { get; protected set; } /// /// Signals to our test framework that the cluster was started externally. The framework will assert this before /// attempting to spin up a cluster. If no node is found the framework will still spin up a node. /// public bool TestAgainstAlreadyRunningOpenSearch { get; protected set; } /// The mode to run the tests under public TestMode Mode { get; protected set; } /// Some test parameters are randomized, these are found under this property public RandomConfiguration Random { get; protected set; } /// The current configuration signals integration tests should be run public bool RunIntegrationTests => Mode == TestMode.Mixed || Mode == TestMode.Integration; /// The current configuration signals unit tests should be run public bool RunUnitTests => Mode == TestMode.Mixed || Mode == TestMode.Unit; /// The current configured seed used for random configuration public int Seed { get; private set; } /// whether the seed was provided externally to be fixated public bool SeedProvidedExternally { get; private set; } /// /// This is fixed for now, specifying false leads to flaky tests, warrants deeper investigation /// in our abstractions project /// public bool ShowOpenSearchOutputAfterStarted { get; } = true; /// When specified will only run one overload in API tests, helpful when debugging locally public bool TestOnlyOne { get; protected set; } private static int CurrentSeed { get; } = new Random().Next(1, 1_00_000); protected void SetExternalSeed(int? seed, out Random randomizer) { SeedProvidedExternally = seed.HasValue; Seed = seed.GetValueOrDefault(CurrentSeed); randomizer = new Random(Seed); } } public class RandomConfiguration { /// Run tests with a custom source serializer rather than the build in one public bool SourceSerializer { get; set; } /// Randomly enable typed keys on searches (defaults to true) on OSC search requests public bool TypedKeys { get; set; } /// Randomly enable compression on the http requests public bool HttpCompression { get; set; } } }