plotly / plotly/dash

Mock synchronisation issues on Windows only (Linux/OSX fine)

Đang mở
#855 7 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug P3 testing
Ngôn ngữ chính
Python
Star
24.4k
Fork
2.3k
Merge trung bình
2 ngày 7 giờ
Pull request đã merge (30 ngày)
13

Mô tả

Describe your context

dash                                    1.1.1
dash-bootstrap-components               0.7.0
dash-core-components                    1.1.1
dash-html-components                    1.0.0
dash-renderer                           1.0.0
dash-table                              4.1.0
selenium                                3.141.0

Previously tested with dash 1.0.2 -- same behaviour observed.

  • Browser, Version and OS

    • OS: Windows 10 Pro
    • Browser: Chrome
    • Version: 76.0.3809.87, 75.0.3770.80 (matched chromedriver version used in both cases)
    • Issue does NOT occur using same Chrome versions on Manjaro Linux or OSX
    • Reproduced on two different machines/Windows 10 installations

Describe the bug

Unit tests using dash-testing / selenium clear_input() / send_keys() methods drive browser input as expected (verified visually -- inserting artificial time.sleep() statements on occasion to be sure). Mocked functions capture some but not all invocations. In some cases, inserting additional calls to clear_input() appears to cause some internal (?inter-process?) synchronisation of the mock to occur, capturing the outstanding invocations. However this is inconsistent -- the workaround shown in the self-contained example below works consistently in that example, but not in other very similar tests in our codebase.

Expected behavior

Mocks record invocations from all callback invocations without need for additional attempts to flush/synchronise. I.e. behaviour consistent with expectations / verified behaviour on Linux and OSX.

Self-contained example

import re
import random
import time
import pytest

import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output, State

import platform

DEFAULT_VALUE = 20
NEW_VALUE = -20

def _build_app_layout():
    app = dash.Dash(__name__)
    app.layout = html.Div(id='top',children=[
      dcc.Input(id='some_input', value=str(DEFAULT_VALUE)),
      html.Div(id='alert_container')
    ])
    @app.callback(Output('alert_container', 'children'),
                  [Input('some_input', 'value')])
    def validate_input(new_value: str):
        if re.match(r'[+-]?\d+',new_value):
            #Nonsense call so we can count num invocations
            _throwaway = random.randint(int(new_value),DEFAULT_VALUE)
            return 'Unmodified' if new_value == str(DEFAULT_VALUE) else 'Modified'
        #Nonsense call so we can count num invocations
        _throwaway = random.randint(0,DEFAULT_VALUE)
        return 'Invalid'
    return app


@pytest.mark.webtest
def test_should_validate_inputs_when_modified(mocker, dash_duo):
    """This is a self-contained test intended to reproduce a problem we've been
    having, where mocked functions invoked from dash callbacks can be verified on
    Linux and OSX, but not on Windows.
    """
    # Given
    mocker.patch('random.randint', return_value=DEFAULT_VALUE)
    dash_duo.start_server(_build_app_layout())
    input_element = dash_duo.find_element('input#some_input')
    initial_value = input_element.get_attribute('value')

    # When
    dash_duo.clear_input(input_element)
    input_element.send_keys(f'{NEW_VALUE}')
    dash_duo.wait_for_contains_text('input#some_input', str(NEW_VALUE), timeout=5)
    # Uncommenting the next two lines causes test to pass on Windows
    #if platform.system() == 'Windows':
    #    dash_duo.clear_input(input_element)

    # Then
    # ... over-elaborated assertions to see error detail
    random.randint.assert_has_calls([
        mocker.call(DEFAULT_VALUE, DEFAULT_VALUE),
        mocker.call(0, DEFAULT_VALUE),# <clear>
        mocker.call(0, DEFAULT_VALUE),# -
        mocker.call(-2, DEFAULT_VALUE),
        mocker.call(-20, DEFAULT_VALUE)
    ])
    # ... actual assertion if we resolve this issue
    random.randint.assert_called_with(NEW_VALUE, DEFAULT_VALUE)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với bài kiểm thử pytest độc lập sử dụng dash_duo, clear_input(), send_keys() và các lệnh gọi random.randint được mock. So sánh việc đồng bộ hóa callback mock trên Windows với Linux và OSX, sau đó xác minh rằng tất cả các lần gọi dự kiến đều được ghi nhận mà không cần workaround clear_input() bổ sung.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
testing
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.