Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test_thread_safety #105

Closed
gspe opened this issue Jan 14, 2021 · 10 comments
Closed

Failing test_thread_safety #105

gspe opened this issue Jan 14, 2021 · 10 comments

Comments

@gspe
Copy link

gspe commented Jan 14, 2021

I'm trying to package pymediainfo for void linux distribution but it fails the thread safety test.

This vesrion of software are used in void

python3-3.9.1_1
libmediainfo-20.09_1

These are some sample of the errors:

FAILED tests/test_pymediainfo.py::test_thread_safety[sample.mkv] - assert {'t...
FAILED tests/test_pymediainfo.py::test_thread_safety[sample.mp4] - AssertionE...
FAILED tests/test_pymediainfo.py::test_thread_safety[mpeg4.mp4] - AssertionEr...
FAILED tests/test_pymediainfo.py::test_thread_safety[mp3.mp3] - AssertionErro...
FAILED tests/test_pymediainfo.py::test_thread_safety[mp4-with-audio.mp4] - As...
=================================== FAILURES ===================================
________________________ test_thread_safety[sample.mkv] ________________________

test_file = 'sample.mkv'

    @pytest.mark.parametrize("test_file", test_media_files)
    def test_thread_safety(test_file):
        lib_version_str, lib_version = _get_library_version()
        if lib_version < (20, 3):
            pytest.skip(
                "This version of the library is not thread-safe "
                "(v{} detected, v20.03 required)".format(lib_version_str)
            )
        expected_result = MediaInfo.parse(os.path.join(data_dir, test_file))
        results = []
        lock = threading.Lock()

        def target():
            try:
                result = MediaInfo.parse(os.path.join(data_dir, test_file))
                with lock:
                    results.append(result)
            except Exception:  # pylint: disable=broad-except
                pass

        threads = []
        thread_count = 100
        for _ in range(thread_count):
            thread = threading.Thread(target=target)
            thread.start()
            threads.append(thread)
        for thread in threads:
            thread.join()
        # Each thread should have produced a result
        assert len(results) == thread_count
        for res in results:
            # Test dicts first because they will show a diff
            # in case they don't match
>           assert res.to_data() == expected_result.to_data()
E           assert {'tracks': [{'commercial_name': 'Matroska',\n             'complete_name': '/builddir/pymediainfo-5.0.3/tests/data/sample.mkv',\n             'count': '331',\n             'count_of_menu_streams': '1',\n             'count_of_stream_of_this_kind': '1',\n             'count_of_text_streams': '1',\n             'encoded_date': 'UTC 2020-11-13 21:48:23',\n             'file_extension': 'mkv',\n             'file_last_modification_date': 'UTC 2020-11-23 23:18:11',\n             'file_last_modification_date__local': '2020-11-23 23:18:11',\n             'file_name': 'sample',\n             'file_name_extension': 'sample.mkv',\n             'file_size': 6096,\n             'folder_name': '/builddir/pymediainfo-5.0.3/tests/data',\n             'format': 'Matroska',\n             'format_extensions_usually_used': 'mkv mk3d mka mks',\n             'format_url': 'https://matroska.org/downloads/windows.html',\n             'format_version': 'Version 1',\n             'isstreamable': 'Yes',\n             'kind_of_stream': 'General',\n             'other_file_size': ['5.95 KiB',\n                                 '6 KiB',\n                                 '6.0 KiB',\n                                 '5.95 KiB',\n                                 '5.953 KiB'],\n             'other_format': ['Matroska'],\n             'other_kind_of_stream': ['General'],\n             'other_stream_size': ['5.95 KiB (100%)',\n                                   '6 KiB',\n                                   '6.0 KiB',\n                                   '5.95 KiB',\n                                   '5.953 KiB',\n                                   '5.95 KiB (100%)'],\n             'other_unique_id': ['316512989421817929798059249096004578493 '\n                                 '(0xEE1E2F35979152ED0AD4120F6DF5ACBD)'],\n             'other_writing_application': ["mkvmerge v45.0.0 ('Heaven in "\n                                           "Pennies') 64-bit"],\n             'other_writing_library': ['libebml v1.3.10 + libmatroska v1.5.2'],\n             'proportion_of_this_stream': '1.00000',\n             'stream_identifier': '0',\n             'stream_size': 6096,\n             'text_codecs': 'UTF-8',\n             'text_format_list': 'UTF-8',\n             'text_format_withhint_list': 'UTF-8',\n             'text_language_list': 'English',\n             'title': 'Dès Noël où un zéphyr haï me vêt de glaçons würmiens je '\n                      'dîne d’exquis rôtis de bœuf au kir à l’aÿ d’âge mûr & '\n                      'cætera !',\n             'track_name': 'Dès Noël où un zéphyr haï me vêt de glaçons '\n                           'würmiens je dîne d’exquis rôtis de bœuf au kir à '\n                           'l’aÿ d’âge mûr & cætera !',\n             'track_type': 'General',\n             'unique_id': 316512989421817929798059249096004578493,\n             'writing_application': "mkvmerge v45.0.0 ('Heaven in Pennies') "\n                                    '64-bit',\n             'writing_library': 'libebml v1.3.10 + libmatroska v1.5.2'},\n            {'bit_rate': 0,\n             'codec_id': 'S_TEXT/UTF8',\n             'codec_id_info': 'UTF-8 Plain Text',\n             'commercial_name': 'UTF-8',\n             'count': '238',\n             'count_of_elements': '0',\n             'count_of_stream_of_this_kind': '1',\n             'default': 'Yes',\n             'duration': '0.000000',\n             'forced': 'No',\n             'format': 'UTF-8',\n             'frame_count': '0',\n             'kind_of_stream': 'Text',\n             'language': 'en',\n             'other_bit_rate': ['0 b/s'],\n             'other_default': ['Yes'],\n             'other_duration': ['00:00:00.000', '00:00:00.000'],\n             'other_forced': ['No'],\n             'other_format': ['UTF-8'],\n             'other_kind_of_stream': ['Text'],\n             'other_language': ['English', 'English', 'en', 'eng', 'en'],\n             'other_stream_size': ['0.00 Byte (0%)',\n                                   ' Byte0',\n                                   '0.0 Byte',\n                                   '0.00 Byte',\n                                   '0.000 Byte',\n                                   '0.00 Byte (0%)'],\n             'other_track_id': ['1'],\n             'proportion_of_this_stream': '0.00000',\n             'stream_identifier': '0',\n             'stream_size': 0,\n             'streamorder': '0',\n             'track_id': 1,\n             'track_type': 'Text',\n             'unique_id': '5079624137464679146'},\n            {'00_00_00000': 'en:Chapter 01',\n             'chapters_pos_begin': '94',\n             'chapters_pos_end': '95',\n             'count': '95',\n             'count_of_stream_of_this_kind': '1',\n             'kind_of_stream': 'Menu',\n             'other_kind_of_stream': ['Menu'],\n             'stream_identifier': '0',\n             'track_type': 'Menu'}]} == {'tracks': [{'commercial_name': 'Matroska',\n             'complete_name': '/builddir/pymediainfo-5.0.3/tests/data/sample.mkv',\n             'count': '331',\n             'count_of_menu_streams': '1',\n             'count_of_stream_of_this_kind': '1',\n             'count_of_text_streams': '1',\n             'encoded_date': 'UTC 2020-11-13 21:48:23',\n             'file_extension': 'mkv',\n             'file_last_modification_date': 'UTC 2020-11-23 23:18:11',\n             'file_last_modification_date__local': '2020-11-24 00:18:11',\n             'file_name': 'sample',\n             'file_name_extension': 'sample.mkv',\n             'file_size': 6096,\n             'folder_name': '/builddir/pymediainfo-5.0.3/tests/data',\n             'format': 'Matroska',\n             'format_extensions_usually_used': 'mkv mk3d mka mks',\n             'format_url': 'https://matroska.org/downloads/windows.html',\n             'format_version': 'Version 1',\n             'isstreamable': 'Yes',\n             'kind_of_stream': 'General',\n             'other_file_size': ['5.95 KiB',\n                                 '6 KiB',\n                                 '6.0 KiB',\n                                 '5.95 KiB',\n                                 '5.953 KiB'],\n             'other_format': ['Matroska'],\n             'other_kind_of_stream': ['General'],\n             'other_stream_size': ['5.95 KiB (100%)',\n                                   '6 KiB',\n                                   '6.0 KiB',\n                                   '5.95 KiB',\n                                   '5.953 KiB',\n                                   '5.95 KiB (100%)'],\n             'other_unique_id': ['316512989421817929798059249096004578493 '\n                                 '(0xEE1E2F35979152ED0AD4120F6DF5ACBD)'],\n             'other_writing_application': ["mkvmerge v45.0.0 ('Heaven in "\n                                           "Pennies') 64-bit"],\n             'other_writing_library': ['libebml v1.3.10 + libmatroska v1.5.2'],\n             'proportion_of_this_stream': '1.00000',\n             'stream_identifier': '0',\n             'stream_size': 6096,\n             'text_codecs': 'UTF-8',\n             'text_format_list': 'UTF-8',\n             'text_format_withhint_list': 'UTF-8',\n             'text_language_list': 'English',\n             'title': 'Dès Noël où un zéphyr haï me vêt de glaçons würmiens je '\n                      'dîne d’exquis rôtis de bœuf au kir à l’aÿ d’âge mûr & '\n                      'cætera !',\n             'track_name': 'Dès Noël où un zéphyr haï me vêt de glaçons '\n                           'würmiens je dîne d’exquis rôtis de bœuf au kir à '\n                           'l’aÿ d’âge mûr & cætera !',\n             'track_type': 'General',\n             'unique_id': 316512989421817929798059249096004578493,\n             'writing_application': "mkvmerge v45.0.0 ('Heaven in Pennies') "\n                                    '64-bit',\n             'writing_library': 'libebml v1.3.10 + libmatroska v1.5.2'},\n            {'bit_rate': 0,\n             'codec_id': 'S_TEXT/UTF8',\n             'codec_id_info': 'UTF-8 Plain Text',\n             'commercial_name': 'UTF-8',\n             'count': '238',\n             'count_of_elements': '0',\n             'count_of_stream_of_this_kind': '1',\n             'default': 'Yes',\n             'duration': '0.000000',\n             'forced': 'No',\n             'format': 'UTF-8',\n             'frame_count': '0',\n             'kind_of_stream': 'Text',\n             'language': 'en',\n             'other_bit_rate': ['0 b/s'],\n             'other_default': ['Yes'],\n             'other_duration': ['00:00:00.000', '00:00:00.000'],\n             'other_forced': ['No'],\n             'other_format': ['UTF-8'],\n             'other_kind_of_stream': ['Text'],\n             'other_language': ['English', 'English', 'en', 'eng', 'en'],\n             'other_stream_size': ['0.00 Byte (0%)',\n                                   ' Byte0',\n                                   '0.0 Byte',\n                                   '0.00 Byte',\n                                   '0.000 Byte',\n                                   '0.00 Byte (0%)'],\n             'other_track_id': ['1'],\n             'proportion_of_this_stream': '0.00000',\n             'stream_identifier': '0',\n             'stream_size': 0,\n             'streamorder': '0',\n             'track_id': 1,\n             'track_type': 'Text',\n             'unique_id': '5079624137464679146'},\n            {'00_00_00000': 'en:Chapter 01',\n             'chapters_pos_begin': '94',\n             'chapters_pos_end': '95',\n             'count': '95',\n             'count_of_stream_of_this_kind': '1',\n             'kind_of_stream': 'Menu',\n             'other_kind_of_stream': ['Menu'],\n             'stream_identifier': '0',\n             'track_type': 'Menu'}]}
E             Differing items:
E             {'tracks': [{'commercial_name': 'Matroska', 'complete_name': '/builddir/pymediainfo-5.0.3/tests/data/sample.mkv', 'cou...-8', ...}, {'00_00_00000': 'en:Chapter 01', 'chapters_pos_begin': '94', 'chapters_pos_end': '95', 'count': '95', ...}]} != {'tracks': [{'commercial_name': 'Matroska', 'complete_name': '/builddir/pymediainfo-5.0.3/tests/data/sample.mkv', 'cou...-8', ...}, {'00_00_00000': 'en:Chapter 01', 'chapters_pos_begin': '94', 'chapters_pos_end': '95', 'count': '95', ...}]}
E             Full diff:
E               {
E                'tracks': [{'commercial_name': 'Matroska',
E                            'complete_name': '/builddir/pymediainfo-5.0.3/tests/data/sample.mkv',
E                            'count': '331',
E                            'count_of_menu_streams': '1',
E                            'count_of_stream_of_this_kind': '1',
E                            'count_of_text_streams': '1',
E                            'encoded_date': 'UTC 2020-11-13 21:48:23',
E                            'file_extension': 'mkv',
E                            'file_last_modification_date': 'UTC 2020-11-23 23:18:11',
E             -              'file_last_modification_date__local': '2020-11-24 00:18:11',
E             ?                                                              ^^^^
E             +              'file_last_modification_date__local': '2020-11-23 23:18:11',
E             ?                                                              ^^^^
E                            'file_name': 'sample',
E                            'file_name_extension': 'sample.mkv',
E                            'file_size': 6096,
E                            'folder_name': '/builddir/pymediainfo-5.0.3/tests/data',
E                            'format': 'Matroska',
E                            'format_extensions_usually_used': 'mkv mk3d mka mks',
E                            'format_url': 'https://matroska.org/downloads/windows.html',
E                            'format_version': 'Version 1',
E                            'isstreamable': 'Yes',
E                            'kind_of_stream': 'General',
E                            'other_file_size': ['5.95 KiB',
E                                                '6 KiB',
E                                                '6.0 KiB',
E                                                '5.95 KiB',
E                                                '5.953 KiB'],
E                            'other_format': ['Matroska'],
E                            'other_kind_of_stream': ['General'],
E                            'other_stream_size': ['5.95 KiB (100%)',
E                                                  '6 KiB',
E                                                  '6.0 KiB',
E                                                  '5.95 KiB',
E                                                  '5.953 KiB',
E                                                  '5.95 KiB (100%)'],
E                            'other_unique_id': ['316512989421817929798059249096004578493 '
E                                                '(0xEE1E2F35979152ED0AD4120F6DF5ACBD)'],
E                            'other_writing_application': ["mkvmerge v45.0.0 ('Heaven in "
E                                                          "Pennies') 64-bit"],
E                            'other_writing_library': ['libebml v1.3.10 + libmatroska v1.5.2'],
E                            'proportion_of_this_stream': '1.00000',
E                            'stream_identifier': '0',
E                            'stream_size': 6096,
E                            'text_codecs': 'UTF-8',
E                            'text_format_list': 'UTF-8',
E                            'text_format_withhint_list': 'UTF-8',
E                            'text_language_list': 'English',
E                            'title': 'Dès Noël où un zéphyr haï me vêt de glaçons würmiens je '
E                                     'dîne d’exquis rôtis de bœuf au kir à l’aÿ d’âge mûr & '
E                                     'cætera !',
E                            'track_name': 'Dès Noël où un zéphyr haï me vêt de glaçons '
E                                          'würmiens je dîne d’exquis rôtis de bœuf au kir à '
E                                          'l’aÿ d’âge mûr & cætera !',
E                            'track_type': 'General',
E                            'unique_id': 316512989421817929798059249096004578493,
E                            'writing_application': "mkvmerge v45.0.0 ('Heaven in Pennies') "
E                                                   '64-bit',
E                            'writing_library': 'libebml v1.3.10 + libmatroska v1.5.2'},
E                           {'bit_rate': 0,
E                            'codec_id': 'S_TEXT/UTF8',
E                            'codec_id_info': 'UTF-8 Plain Text',
E                            'commercial_name': 'UTF-8',
E                            'count': '238',
E                            'count_of_elements': '0',
E                            'count_of_stream_of_this_kind': '1',
E                            'default': 'Yes',
E                            'duration': '0.000000',
E                            'forced': 'No',
E                            'format': 'UTF-8',
E                            'frame_count': '0',
E                            'kind_of_stream': 'Text',
E                            'language': 'en',
E                            'other_bit_rate': ['0 b/s'],
E                            'other_default': ['Yes'],
E                            'other_duration': ['00:00:00.000', '00:00:00.000'],
E                            'other_forced': ['No'],
E                            'other_format': ['UTF-8'],
E                            'other_kind_of_stream': ['Text'],
E                            'other_language': ['English', 'English', 'en', 'eng', 'en'],
E                            'other_stream_size': ['0.00 Byte (0%)',
E                                                  ' Byte0',
E                                                  '0.0 Byte',
E                                                  '0.00 Byte',
E                                                  '0.000 Byte',
E                                                  '0.00 Byte (0%)'],
E                            'other_track_id': ['1'],
E                            'proportion_of_this_stream': '0.00000',
E                            'stream_identifier': '0',
E                            'stream_size': 0,
E                            'streamorder': '0',
E                            'track_id': 1,
E                            'track_type': 'Text',
E                            'unique_id': '5079624137464679146'},
E                           {'00_00_00000': 'en:Chapter 01',
E                            'chapters_pos_begin': '94',
E                            'chapters_pos_end': '95',
E                            'count': '95',
E                            'count_of_stream_of_this_kind': '1',
E                            'kind_of_stream': 'Menu',
E                            'other_kind_of_stream': ['Menu'],
E                            'stream_identifier': '0',
E                            'track_type': 'Menu'}],
E               }

tests/test_pymediainfo.py:341: AssertionError

@sbraz
Copy link
Owner

sbraz commented Jan 14, 2021

Hi,
What filesystem are you using? It looks like the mtime of the file changes between calls.

E - 'file_last_modification_date__local': '2020-11-24 00:18:11',
E ? ^^^^
E + 'file_last_modification_date__local': '2020-11-23 23:18:11',
E ? ^^^^

@sbraz
Copy link
Owner

sbraz commented Jan 14, 2021

My bad, it's not the mtime itself that changes but the time zone, weird.

@sbraz
Copy link
Owner

sbraz commented Jan 14, 2021

What do you get if you run this?

#!/usr/bin/env python3

import threading
import time


def test():
    print("From created thread:", time.tzname)


print("From main thread:", time.tzname)
t = threading.Thread(target=test)
t.start()
t.join()

Here, both threads show the same:

From main thread: ('CET', 'CEST')
From created thread: ('CET', 'CEST')

@gspe
Copy link
Author

gspe commented Jan 14, 2021

Hi, sorry for late answer.

My filesystem is zfs, your test code give me

./test-time.py
From main thread: ('CET', 'CEST')
From created thread: ('CET', 'CEST')

Fail errors are different for every compile, sometime 5 tests fails some time 3 tests fails, I also get this kind of error:

E             -              'tagged_date': 'UTC 2016-02-06 00:53:22',
E             ?                                         ^^^^^^^^  ^^
E             +              'tagged_date': 'UTC 2016-011-23 23:18:11',
E             ?                                        +++ ^^^  ^^^^^

@JeromeMartinez
Copy link

It may be a MediaInfo (not the pymediainfo binding) issue, with a fix available but not yet with a public release.
Can you try with a libzen snapshot?

@sbraz
Copy link
Owner

sbraz commented Jan 14, 2021

@JeromeMartinez I had completely forgotten about that, thanks for your help :) v0.4.38 has been released publicly though, hasn't it?

@gspe I'm 99% sure Jérôme is right and I see void is shipping v0.4.37 of libzen, I'll let you update it and close the issue if it works.

@JeromeMartinez
Copy link

@sbraz oops, true, v0.4.38 was release so @gspe needs to confirm if it is tested with libzen v0.4.38+.

@gspe
Copy link
Author

gspe commented Jan 14, 2021

Ok, upgrading libzen to v0.4.38 solve the problem.

Thank you guys.

gspe pushed a commit to gspe/void-packages that referenced this issue Jan 14, 2021
This version solve thread safety problem
sbraz/pymediainfo#105
@ericonr
Copy link

ericonr commented Jan 14, 2021

@JeromeMartinez please see my comments under void-linux/void-packages#27936 (comment) , your fix isn't applied for libraries such as musl (and possibly some BSDs). As you can see in https://man.voidlinux.org/feature_test_macros.7 , feature test macros should be defined by the application and tested by the system headers (yes, the naming is terrible); you shouldn't try to check their values in your own code.

I suggested a fix in my comments, and I would suggest not supporting a case where neither gmtime_r or gmtime_s are available at all, since that means those versions of the library aren't thread safe. gmtime_r should be available in most places.

@sbraz
Copy link
Owner

sbraz commented Jan 27, 2021

I'm closing this as it has to do with MediaInfo itself. @JeromeMartinez I'll let you look at @ericonr's comments with regards to non-libc systems.

@sbraz sbraz closed this as completed Jan 27, 2021
ericonr pushed a commit to void-linux/void-packages that referenced this issue Feb 15, 2021
This version + patch applied by ericonr solve thread safety problem
sbraz/pymediainfo#105

Also by ericonr:
- don't use create_wrksrc unnecessarily

Closes: #27936 [via git-merge-pr]
hazayan pushed a commit to hazayan/void-packages that referenced this issue Feb 28, 2021
This version + patch applied by ericonr solve thread safety problem
sbraz/pymediainfo#105

Also by ericonr:
- don't use create_wrksrc unnecessarily

Closes: void-linux#27936 [via git-merge-pr]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants