Skip to content

Commit 06b28e7

Browse files
committed
test(discovery v1): Updated integration tests to wait for collection
1 parent e1c2c02 commit 06b28e7

File tree

1 file changed

+84
-2
lines changed

1 file changed

+84
-2
lines changed

test/IBM.WatsonDeveloperCloud.Discovery.v1.IntegrationTests/DiscoveryIntegrationTests.cs

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,9 @@ public void TestTokenization_Success()
762762
var createCollectionResult = CreateCollection(environmentId, createCollectionRequest);
763763
var tokenizationCollectionId = createCollectionResult.CollectionId;
764764

765+
IsCollectionReady(environmentId, tokenizationCollectionId);
766+
autoEvent.WaitOne();
767+
765768
TokenDict tokenizationDictionary = new TokenDict()
766769
{
767770
TokenizationRules = new List<TokenDictRule>()
@@ -782,10 +785,17 @@ public void TestTokenization_Success()
782785
}
783786
};
784787

788+
IsEnvironmentReady(environmentId);
789+
autoEvent.WaitOne();
790+
785791
try
786792
{
787793
var createTokenizationDictionaryResult = CreateTokenizationDictionary(environmentId, tokenizationCollectionId, tokenizationDictionary);
788794
var getTokenizationDictionaryStatusResult = GetTokenizationDictionaryStatus(environmentId, tokenizationCollectionId);
795+
796+
IsDictionaryReady(environmentId, tokenizationCollectionId);
797+
autoEvent.WaitOne();
798+
789799
var deleteTokenizationDictionary = DeleteTokenizationDictionary(environmentId, tokenizationCollectionId);
790800

791801
Assert.IsNotNull(deleteTokenizationDictionary);
@@ -821,16 +831,22 @@ public void TestStopword_Success()
821831
}
822832
}
823833

834+
IsEnvironmentReady(environmentId);
835+
autoEvent.WaitOne();
836+
824837
CreateCollectionRequest createCollectionRequest = new CreateCollectionRequest()
825838
{
826-
Language = CreateCollectionRequest.LanguageEnum.JA,
827-
Name = "tokenization-collection-please-delete-" + Guid.NewGuid(),
839+
Language = CreateCollectionRequest.LanguageEnum.EN,
840+
Name = "stopword-collection-please-delete-" + Guid.NewGuid(),
828841
Description = createdCollectionDescription
829842
};
830843

831844
var createCollectionResult = CreateCollection(environmentId, createCollectionRequest);
832845
var stopwordCollectionId = createCollectionResult.CollectionId;
833846

847+
IsCollectionReady(environmentId, stopwordCollectionId);
848+
autoEvent.WaitOne();
849+
834850
TokenDictStatusResponse createStopwordListResult;
835851
using (FileStream fs = File.OpenRead(stopwordFileToIngest))
836852
{
@@ -893,6 +909,72 @@ private void IsEnvironmentReady(string environmentId)
893909
}
894910
#endregion
895911

912+
#region IsDictionaryReady
913+
private void IsDictionaryReady(string environmentId, string tokenizationCollectionId)
914+
{
915+
var result = service.GetTokenizationDictionaryStatus(environmentId, tokenizationCollectionId);
916+
Console.WriteLine(string.Format("\tTokenization dictionary {0} status is {1}.", environmentId, result.Status));
917+
918+
if(result.Status == TokenDictStatusResponse.StatusEnum.ACTIVE)
919+
{
920+
autoEvent.Set();
921+
}
922+
else
923+
{
924+
Task.Factory.StartNew(() =>
925+
{
926+
Thread.Sleep(30000);
927+
Console.WriteLine("Checking tokenization dictionary status in 30 seconds...");
928+
IsDictionaryReady(environmentId, tokenizationCollectionId);
929+
});
930+
}
931+
}
932+
#endregion
933+
934+
#region IsStopwordsReady
935+
private void IsStopwordsReady(string environmentId, string tokenizationCollectionId)
936+
{
937+
var result = service.GetTokenizationDictionaryStatus(environmentId, tokenizationCollectionId);
938+
Console.WriteLine(string.Format("\tTokenization dictionary {0} status is {1}.", environmentId, result.Status));
939+
940+
if (result.Status == TokenDictStatusResponse.StatusEnum.ACTIVE)
941+
{
942+
autoEvent.Set();
943+
}
944+
else
945+
{
946+
Task.Factory.StartNew(() =>
947+
{
948+
Thread.Sleep(30000);
949+
Console.WriteLine("Checking tokenization dictionary status in 30 seconds...");
950+
IsStopwordsReady(environmentId, tokenizationCollectionId);
951+
});
952+
}
953+
}
954+
#endregion
955+
956+
#region IsCollectionReady
957+
private void IsCollectionReady(string environmentId, string collectionId)
958+
{
959+
var result = service.GetCollection(environmentId, collectionId);
960+
Console.WriteLine(string.Format("\tCollection {0} status is {1}.", environmentId, result.Status));
961+
962+
if (result.Status == Collection.StatusEnum.ACTIVE)
963+
{
964+
autoEvent.Set();
965+
}
966+
else
967+
{
968+
Task.Factory.StartNew(() =>
969+
{
970+
Thread.Sleep(30000);
971+
Console.WriteLine("Checking collection status in 30 seconds...");
972+
IsCollectionReady(environmentId, collectionId);
973+
});
974+
}
975+
}
976+
#endregion
977+
896978
#region Generated
897979
#region CreateEnvironment
898980
private Environment CreateEnvironment(CreateEnvironmentRequest body, Dictionary<string, object> customData = null)

0 commit comments

Comments
 (0)