Skip to content

Commit 3d61c0a

Browse files
committed
Add tests configuration option to allow skipping of plugin verification
skip_plugin_verification: true Handy when running tests against an already running instance.
1 parent 235c708 commit 3d61c0a

File tree

8 files changed

+51
-23
lines changed

8 files changed

+51
-23
lines changed

src/Tests/Framework/Configuration/EnvironmentConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class EnvironmentConfiguration : TestConfigurationBase
1212
public override bool ForceReseed { get; protected set; } = true;
1313
public override string ElasticsearchVersion { get; protected set; }
1414
public override TestMode Mode { get; protected set; } = TestMode.Unit;
15+
public override bool SkipPluginVerification { get; protected set; } = false;
1516

1617
public EnvironmentConfiguration()
1718
{

src/Tests/Framework/Configuration/ITestConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public interface ITestConfiguration
1010
{
1111
TestMode Mode { get; }
1212
string ElasticsearchVersion { get; }
13-
bool ForceReseed { get; }
13+
bool ForceReseed { get; }
1414
bool DoNotSpawnIfAlreadyRunning { get; }
15-
15+
bool SkipPluginVerification { get; }
1616
bool RunIntegrationTests { get; }
1717
bool RunUnitTests { get; }
1818
}

src/Tests/Framework/Configuration/TestConfigurationBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ public abstract class TestConfigurationBase : ITestConfiguration
1010
{
1111
public abstract bool DoNotSpawnIfAlreadyRunning { get; protected set; }
1212
public abstract string ElasticsearchVersion { get; protected set; }
13-
public abstract bool ForceReseed { get; protected set; }
13+
public abstract bool ForceReseed { get; protected set; }
1414
public abstract TestMode Mode { get; protected set; }
15+
public abstract bool SkipPluginVerification { get; protected set; }
1516

1617
public virtual bool RunIntegrationTests => Mode == TestMode.Mixed || Mode == TestMode.Integration;
1718
public virtual bool RunUnitTests => Mode == TestMode.Mixed || Mode == TestMode.Unit;

src/Tests/Framework/Configuration/YamlConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ public class YamlConfiguration : TestConfigurationBase
1010
public override string ElasticsearchVersion { get; protected set; } = "2.0.0";
1111
public override bool ForceReseed { get; protected set; } = true;
1212
public override TestMode Mode { get; protected set; } = TestMode.Unit;
13+
public override bool SkipPluginVerification { get; protected set; } = false;
1314

1415

1516
public YamlConfiguration(string configurationFile)
1617
{
1718
if (!File.Exists(configurationFile)) return;
1819

1920
var config = File.ReadAllLines(configurationFile)
20-
.Where(l=>!l.Trim().StartsWith("#"))
21+
.Where(l=> !string.IsNullOrEmpty(l) && !l.Trim().StartsWith("#"))
2122
.ToDictionary(ConfigName, ConfigValue);
2223

2324
this.Mode = GetTestMode(config["mode"]);
2425
this.ElasticsearchVersion = config["elasticsearch_version"];
2526
this.ForceReseed = bool.Parse(config["force_reseed"]);
2627
this.DoNotSpawnIfAlreadyRunning = bool.Parse(config["do_not_spawn"]);
28+
this.SkipPluginVerification = bool.Parse(config["skip_plugin_verification"]);
2729
}
2830

2931
private static string ConfigName(string configLine) => Parse(configLine, 0);

src/Tests/Framework/Integration/Clusters/ClusterBase.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ public abstract class ClusterBase : IIntegrationCluster, IDisposable
1515

1616
protected ClusterBase()
1717
{
18-
var name = this.GetType().Name.Replace("Cluster", "");
19-
this.Node = new ElasticsearchNode(TestClient.Configuration.ElasticsearchVersion, TestClient.Configuration.RunIntegrationTests, DoNotSpawnIfAlreadyRunning, name, EnableShield);
18+
var name = this.GetType().Name.Replace("Cluster", "");
19+
20+
this.Node = new ElasticsearchNode(
21+
TestClient.Configuration.ElasticsearchVersion,
22+
TestClient.Configuration.RunIntegrationTests,
23+
DoNotSpawnIfAlreadyRunning,
24+
name,
25+
EnableShield,
26+
TestClient.Configuration.SkipPluginVerification
27+
);
28+
2029
this.Node.BootstrapWork.Subscribe(handle =>
2130
{
2231
this.Boostrap();
2332
handle.Set();
2433
});
34+
2535
this.ConsoleOut = this.Node.Start(name, this.ServerSettings);
2636
}
2737

src/Tests/Framework/Integration/Process/ElasticsearchNode.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ElasticsearchNode : IDisposable
3434

3535
private readonly bool _doNotSpawnIfAlreadyRunning;
3636
private readonly bool _shieldEnabled;
37+
private readonly bool _skipPluginVerification;
3738
private ObservableProcess _process;
3839
private IDisposable _processListener;
3940

@@ -103,11 +104,13 @@ public ElasticsearchNode(
103104
bool runningIntegrations,
104105
bool doNotSpawnIfAlreadyRunning,
105106
string name,
106-
bool shieldEnabled
107+
bool shieldEnabled,
108+
bool skipPluginVerification
107109
)
108110
{
109111
this._doNotSpawnIfAlreadyRunning = doNotSpawnIfAlreadyRunning;
110112
this._shieldEnabled = shieldEnabled;
113+
this._skipPluginVerification = skipPluginVerification;
111114

112115
var prefix = name.ToLowerInvariant();
113116
var suffix = Guid.NewGuid().ToString("N").Substring(0, 6);
@@ -212,9 +215,9 @@ public IObservable<ElasticsearchMessage> Start(string typeOfCluster, string[] ad
212215

213216
if (handle.WaitOne(this.HandleTimeout, true)) return observable;
214217

215-
this.Stop();
218+
this.Stop();
216219
throw new Exception($"Could not start elasticsearch within {this.HandleTimeout}");
217-
}
220+
}
218221

219222
#if DOTNETCORE
220223
private IObservable<ElasticsearchMessage> UseAlreadyRunningInstance(Signal handle)
@@ -229,11 +232,13 @@ private IObservable<ElasticsearchMessage> UseAlreadyRunningInstance(ManualResetE
229232

230233
if (!alreadyUp.IsValid) return null;
231234

232-
var checkPlugins = client.CatPlugins();
233-
234-
var missingPlugins = SupportedPlugins.Keys.Except(checkPlugins.Records.Select(r => r.Component)).ToList();
235-
if (missingPlugins.Any())
236-
throw new Exception($"Already running elasticsearch missed the following plugin(s): {string.Join(", ", missingPlugins)}.");
235+
if (!_skipPluginVerification)
236+
{
237+
var checkPlugins = client.CatPlugins();
238+
var missingPlugins = SupportedPlugins.Keys.Except(checkPlugins.Records.Select(r => r.Component)).ToList();
239+
if (missingPlugins.Any())
240+
throw new Exception($"Already running elasticsearch missed the following plugin(s): {string.Join(", ", missingPlugins)}.");
241+
}
237242

238243
this.Started = true;
239244
this.Port = 9200;
@@ -247,6 +252,8 @@ private IObservable<ElasticsearchMessage> UseAlreadyRunningInstance(ManualResetE
247252
return Observable.Empty<ElasticsearchMessage>();
248253
}
249254

255+
private static object _licenseLock = new object();
256+
250257
private void ValidateLicense()
251258
{
252259
var client = TestClient.GetClient();
@@ -278,8 +285,6 @@ private void ValidateLicense()
278285

279286
if (license.License.Status == LicenseStatus.Invalid)
280287
throw new Exception($"{exceptionMessageStart} but the license is invalid!");
281-
282-
283288
}
284289

285290
#if DOTNETCORE

src/Tests/Framework/MockData/Project.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class Project
2222
public SimpleGeoPoint Location { get; set; }
2323
public int? NumberOfCommits { get; set; }
2424
public CompletionField Suggest { get; set; }
25+
public IList<string> Branches { get; set; }
2526

2627
public static Faker<Project> Generator { get; } =
2728
new Faker<Project>()

src/Tests/tests.yaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: u
3-
# the elasticsearch version that should be started
4-
elasticsearch_version: 5.0.0-alpha1
5-
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running
1+
# Dictates what types of tests should be run.
2+
# Can be "u" (unit tests), "i" (integration tests) or "m" (mixed: run both unit and integration tests)
3+
mode: m
4+
5+
# The elasticsearch version that should be started
6+
elasticsearch_version: 5.0.0-alpha2-SNAPSHOT
7+
8+
# Whether we want to forcefully reseed on the node, if you are starting the tests with a node already running
69
force_reseed: true
7-
# do not spawn nodes as part of the test setup but rely on a manually started es node being up
8-
do_not_spawn: true
10+
11+
# Do not spawn nodes as part of the test setup but instead rely on a manually started ES node being up
12+
do_not_spawn: true
13+
14+
# Skip verification of installed plugins on an already running node.
15+
# Useful for quickly running integration tests that do not rely on any plugins being installed.
16+
skip_plugin_verification: true

0 commit comments

Comments
 (0)