@@ -41,18 +41,20 @@ public DefaultSeeder(IElasticClient client) : this(client, null) { }
4141
4242 public void SeedNode ( )
4343 {
44- if ( ! TestClient . Configuration . ForceReseed && AlreadySeeded ( ) ) return ;
44+ var alreadySeeded = false ;
45+ if ( ! TestClient . Configuration . ForceReseed && ( alreadySeeded = AlreadySeeded ( ) ) ) return ;
4546
46- var t = Task . Run ( async ( ) => await SeedNodeAsync ( ) ) ;
47+ var t = Task . Run ( async ( ) => await SeedNodeAsync ( alreadySeeded ) . ConfigureAwait ( false ) ) ;
4748
4849 t . Wait ( TimeSpan . FromSeconds ( 40 ) ) ;
4950 }
5051
5152 public void SeedNodeNoData ( )
5253 {
53- if ( ! TestClient . Configuration . ForceReseed && AlreadySeeded ( ) ) return ;
54+ var alreadySeeded = false ;
55+ if ( ! TestClient . Configuration . ForceReseed && ( alreadySeeded = AlreadySeeded ( ) ) ) return ;
5456
55- var t = Task . Run ( async ( ) => await SeedNodeNoDataAsync ( ) ) ;
57+ var t = Task . Run ( async ( ) => await SeedNodeNoDataAsync ( alreadySeeded ) . ConfigureAwait ( false ) ) ;
5658
5759 t . Wait ( TimeSpan . FromSeconds ( 40 ) ) ;
5860 }
@@ -62,23 +64,23 @@ public void SeedNodeNoData()
6264 // If raw_fields exists assume this cluster is already seeded.
6365 private bool AlreadySeeded ( ) => Client . Indices . TemplateExists ( TestsIndexTemplateName ) . Exists ;
6466
65- private async Task SeedNodeAsync ( )
67+ private async Task SeedNodeAsync ( bool alreadySeeded )
6668 {
6769 // Ensure a clean slate by deleting everything regardless of whether they may already exist
68- await DeleteIndicesAndTemplatesAsync ( ) ;
69- await ClusterSettingsAsync ( ) ;
70- await PutPipeline ( ) ;
70+ await DeleteIndicesAndTemplatesAsync ( alreadySeeded ) . ConfigureAwait ( false ) ;
71+ await ClusterSettingsAsync ( ) . ConfigureAwait ( false ) ;
72+ await PutPipeline ( ) . ConfigureAwait ( false ) ;
7173 // and now recreate everything
72- await CreateIndicesAndSeedIndexDataAsync ( ) ;
74+ await CreateIndicesAndSeedIndexDataAsync ( ) . ConfigureAwait ( false ) ;
7375 }
7476
75- private async Task SeedNodeNoDataAsync ( )
77+ private async Task SeedNodeNoDataAsync ( bool alreadySeeded )
7678 {
7779 // Ensure a clean slate by deleting everything regardless of whether they may already exist
78- await DeleteIndicesAndTemplatesAsync ( ) ;
79- await ClusterSettingsAsync ( ) ;
80+ await DeleteIndicesAndTemplatesAsync ( alreadySeeded ) . ConfigureAwait ( false ) ;
81+ await ClusterSettingsAsync ( ) . ConfigureAwait ( false ) ;
8082 // and now recreate everything
81- await CreateIndicesAsync ( ) ;
83+ await CreateIndicesAsync ( ) . ConfigureAwait ( false ) ;
8284 }
8385
8486 public async Task ClusterSettingsAsync ( )
@@ -99,7 +101,7 @@ public async Task ClusterSettingsAsync()
99101 var putSettingsResponse = await Client . Cluster . PutSettingsAsync ( new ClusterPutSettingsRequest
100102 {
101103 Transient = clusterConfiguration
102- } ) ;
104+ } ) . ConfigureAwait ( false ) ;
103105
104106 putSettingsResponse . ShouldBeValid ( ) ;
105107 }
@@ -113,32 +115,35 @@ public async Task PutPipeline()
113115 . Processors ( pp => pp
114116 . Set < Project > ( s => s . Field ( p => p . Metadata ) . Value ( new { x = "y" } ) )
115117 )
116- ) ;
118+ ) . ConfigureAwait ( false ) ;
117119 putProcessors . ShouldBeValid ( ) ;
118120 }
119121
120122
121- public async Task DeleteIndicesAndTemplatesAsync ( )
123+ public async Task DeleteIndicesAndTemplatesAsync ( bool alreadySeeded )
122124 {
123- var tasks = new Task [ ]
125+ var tasks = new List < Task >
124126 {
125- Client . Indices . DeleteTemplateAsync ( TestsIndexTemplateName ) ,
126127 Client . Indices . DeleteAsync ( typeof ( Project ) ) ,
127128 Client . Indices . DeleteAsync ( typeof ( Developer ) ) ,
128129 Client . Indices . DeleteAsync ( typeof ( ProjectPercolation ) )
129130 } ;
130- await Task . WhenAll ( tasks ) ;
131+
132+ if ( alreadySeeded )
133+ tasks . Add ( Client . Indices . DeleteTemplateAsync ( TestsIndexTemplateName ) ) ;
134+
135+ await Task . WhenAll ( tasks . ToArray ( ) ) . ConfigureAwait ( false ) ;
131136 }
132137
133138 private async Task CreateIndicesAndSeedIndexDataAsync ( )
134139 {
135- await CreateIndicesAsync ( ) ;
136- await SeedIndexDataAsync ( ) ;
140+ await CreateIndicesAsync ( ) . ConfigureAwait ( false ) ;
141+ await SeedIndexDataAsync ( ) . ConfigureAwait ( false ) ;
137142 }
138143
139144 public async Task CreateIndicesAsync ( )
140145 {
141- var indexTemplateResponse = await CreateIndexTemplateAsync ( ) ;
146+ var indexTemplateResponse = await CreateIndexTemplateAsync ( ) . ConfigureAwait ( false ) ;
142147 indexTemplateResponse . ShouldBeValid ( ) ;
143148
144149 var tasks = new [ ]
@@ -152,7 +157,7 @@ await Task.WhenAll(tasks)
152157 {
153158 foreach ( var r in t . Result )
154159 r . ShouldBeValid ( ) ;
155- } ) ;
160+ } ) . ConfigureAwait ( false ) ;
156161 }
157162
158163 private async Task SeedIndexDataAsync ( )
@@ -172,8 +177,8 @@ private async Task SeedIndexDataAsync()
172177 ( d , c ) => d . Document ( c ) . Routing ( c . ProjectName )
173178 )
174179 ) } ;
175- await Task . WhenAll ( tasks ) ;
176- await Client . Indices . RefreshAsync ( Indices . Index ( typeof ( Project ) , typeof ( Developer ) , typeof ( ProjectPercolation ) ) ) ;
180+ await Task . WhenAll ( tasks ) . ConfigureAwait ( false ) ;
181+ await Client . Indices . RefreshAsync ( Indices . Index ( typeof ( Project ) , typeof ( Developer ) , typeof ( ProjectPercolation ) ) ) . ConfigureAwait ( false ) ;
177182 }
178183
179184 private Task < PutIndexTemplateResponse > CreateIndexTemplateAsync ( ) => Client . Indices . PutTemplateAsync (
0 commit comments