Skip to content

Commit

Permalink
dialogflow: make flaky test more generic [(#2936)](#2936)
Browse files Browse the repository at this point in the history
* dialogflow: make flaky test more generic

* use uuid instead of datetime to avoid conflicts when parallel tests are run

Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
  • Loading branch information
2 people authored and dandhlee committed Feb 6, 2023
1 parent 2911055 commit b23f1ca
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 66 deletions.
6 changes: 3 additions & 3 deletions dialogflow/context_management_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import context_management
import detect_intent_texts

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_session_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
CONTEXT_ID = 'test_context_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_session_{}'.format(uuid.uuid4())
CONTEXT_ID = 'test_context_{}'.format(uuid.uuid4())


def test_create_context(capsys):
Expand Down
8 changes: 3 additions & 5 deletions dialogflow/create_document_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import dialogflow_v2beta1 as dialogflow
import pytest

import document_management

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
KNOWLEDGE_BASE_NAME = 'knowledge_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
DOCUMENT_DISPLAY_NAME = 'test_document_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
DOCUMENT_DISPLAY_NAME = 'test_document_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None


Expand Down
4 changes: 2 additions & 2 deletions dialogflow/create_entity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30]
ENTITY_VALUE_1 = "test_entity_value_1"
ENTITY_VALUE_2 = "test_entity_value_2"
SYNONYMS = ["fake_synonym_for_testing_1", "fake_synonym_for_testing_2"]
Expand Down
6 changes: 2 additions & 4 deletions dialogflow/create_entity_type_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_type_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_type_" + datetime.datetime.now().strftime(
"%Y%m%d%H%M%S"
)
DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30]
pytest.ENTITY_TYPE_ID = None


Expand Down
5 changes: 2 additions & 3 deletions dialogflow/create_knowledge_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2beta1 as dialogflow

import knowledge_base_management

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
KNOWLEDGE_BASE_NAME = 'knowledge_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None


Expand Down
8 changes: 3 additions & 5 deletions dialogflow/delete_document_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import dialogflow_v2beta1 as dialogflow
import pytest

import document_management

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
KNOWLEDGE_BASE_NAME = 'knowledge_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
DOCUMENT_DISPLAY_NAME = 'test_document_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
DOCUMENT_DISPLAY_NAME = 'test_document_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None
pytest.DOCUMENT_ID = None

Expand Down
4 changes: 2 additions & 2 deletions dialogflow/delete_entity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30]
ENTITY_VALUE_1 = "test_delete_entity_value"

pytest.ENTITY_TYPE_ID = None
Expand Down
6 changes: 2 additions & 4 deletions dialogflow/delete_entity_type_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_type_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_type_" + datetime.datetime.now().strftime(
"%Y%m%d%H%M%S"
)
DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30]
pytest.ENTITY_TYPE_ID = None


Expand Down
5 changes: 2 additions & 3 deletions dialogflow/delete_knowledge_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import dialogflow_v2beta1 as dialogflow
import pytest

import knowledge_base_management

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
KNOWLEDGE_BASE_NAME = 'knowledge_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None


Expand Down
4 changes: 2 additions & 2 deletions dialogflow/detect_intent_audio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_audio import detect_intent_audio

DIRNAME = os.path.realpath(os.path.dirname(__file__))
PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
AUDIOS = [
'{0}/resources/book_a_room.wav'.format(DIRNAME),
'{0}/resources/mountain_view.wav'.format(DIRNAME),
Expand Down
4 changes: 2 additions & 2 deletions dialogflow/detect_intent_knowledge_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import detect_intent_knowledge

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'session_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'session_{}'.format(uuid.uuid4())
KNOWLEDGE_BASE_ID = 'MjEwMjE4MDQ3MDQwMDc0NTQ3Mg'
TEXTS = ['Where is my data stored?']

Expand Down
8 changes: 4 additions & 4 deletions dialogflow/detect_intent_stream_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_stream import detect_intent_stream

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
AUDIO_FILE_PATH = '{0}/resources/book_a_room.wav'.format(
os.path.realpath(os.path.dirname(__file__)),
)
Expand All @@ -29,5 +29,5 @@ def test_detect_intent_stream(capsys):
detect_intent_stream(PROJECT_ID, SESSION_ID, AUDIO_FILE_PATH, 'en-US')
out, _ = capsys.readouterr()

assert 'Intermediate transcript: "book"' in out
assert 'Fulfillment text: What time will the meeting start?' in out
assert 'Intermediate transcript:' in out
assert 'Fulfillment text:' in out
4 changes: 2 additions & 2 deletions dialogflow/detect_intent_texts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_texts import detect_intent_texts

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
TEXTS = ["hello", "book a meeting room", "Mountain View",
"tomorrow", "10 AM", "2 hours", "10 people", "A", "yes"]

Expand Down
4 changes: 2 additions & 2 deletions dialogflow/detect_intent_with_model_selection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_with_model_selection import \
detect_intent_with_model_selection

DIRNAME = os.path.realpath(os.path.dirname(__file__))
PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
AUDIOS = [
'{0}/resources/book_a_room.wav'.format(DIRNAME),
'{0}/resources/mountain_view.wav'.format(DIRNAME),
Expand Down
4 changes: 2 additions & 2 deletions dialogflow/detect_intent_with_sentiment_analysis_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_with_sentiment_analysis import \
detect_intent_with_sentiment_analysis

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
TEXTS = ["hello", "book a meeting room", "Mountain View",
"tomorrow", "10 AM", "2 hours", "10 people", "A", "yes"]

Expand Down
4 changes: 2 additions & 2 deletions dialogflow/detect_intent_with_texttospeech_response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

from __future__ import absolute_import

import datetime
import os
import uuid

from detect_intent_with_texttospeech_response import \
detect_intent_with_texttospeech_response

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
SESSION_ID = 'test_' + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
SESSION_ID = 'test_{}'.format(uuid.uuid4())
TEXTS = ["hello"]


Expand Down
5 changes: 2 additions & 3 deletions dialogflow/get_knowledge_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import dialogflow_v2beta1 as dialogflow
import pytest

import knowledge_base_management

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
KNOWLEDGE_BASE_NAME = 'knowledge_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
KNOWLEDGE_BASE_NAME = 'knowledge_{}'.format(uuid.uuid4())
pytest.KNOWLEDGE_BASE_ID = None


Expand Down
5 changes: 2 additions & 3 deletions dialogflow/intent_management_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

from __future__ import absolute_import

import datetime
import os
import uuid

import intent_management

PROJECT_ID = os.getenv('GCLOUD_PROJECT')
INTENT_DISPLAY_NAME = 'test_' \
+ datetime.datetime.now().strftime("%Y%m%d%H%M%S")
INTENT_DISPLAY_NAME = 'test_{}'.format(uuid.uuid4())
MESSAGE_TEXTS = [
'fake_message_text_for_testing_1',
'fake_message_text_for_testing_2'
Expand Down
4 changes: 2 additions & 2 deletions dialogflow/list_entities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
DISPLAY_NAME = "entity_{}".format(uuid.uuid4()).replace('-', '')[:30]
ENTITY_VALUE_1 = "test_list_entity_value"

pytest.ENTITY_TYPE_ID = None
Expand Down
6 changes: 2 additions & 4 deletions dialogflow/list_entity_types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@

from __future__ import absolute_import

import datetime
import os
import uuid
import pytest

import dialogflow_v2 as dialogflow

import entity_type_management

PROJECT_ID = os.getenv("GCLOUD_PROJECT")
DISPLAY_NAME = "entity_type_" + datetime.datetime.now().strftime(
"%Y%m%d%H%M%S"
)
DISPLAY_NAME = "entity_type_{}".format(uuid.uuid4()).replace('-', '')[:30]


@pytest.fixture(scope="function", autouse=True)
Expand Down
Loading

0 comments on commit b23f1ca

Please sign in to comment.