Use the default generated pool for some message factory tests.

Use the default generated pool for some message factory tests. Use a new descriptor
pool each time may turns out flake refleck test -- garbage collectors aren't
very predictable.

For blaze test third_party/py/google/protobuf/internal:message_factory_test_python_protos --runs_per_test_detects_flakes --runs_per_test=1000 --copt=-DPy_DEBUG

There were 30-50 failures before the change. Now tests are passing

PiperOrigin-RevId: 546091823
pull/13233/head
Jie Luo 1 year ago committed by Copybara-Service
parent 0cb139cf9e
commit a734d12d61
  1. 40
      python/google/protobuf/internal/message_factory_test.py

@ -122,7 +122,8 @@ class MessageFactoryTest(unittest.TestCase):
# Get messages should work when a file comes before its dependencies:
# factory_test2_fd comes before factory_test1_fd.
messages = message_factory.GetMessages([self.factory_test2_fd,
self.factory_test1_fd])
self.factory_test1_fd],
descriptor_pool.Default())
self.assertTrue(
set(['google.protobuf.python.internal.Factory2Message',
'google.protobuf.python.internal.Factory1Message'],
@ -256,17 +257,13 @@ class MessageFactoryTest(unittest.TestCase):
extendee='Container',
)
class SimpleDescriptorDB:
def __init__(self, files):
self._files = files
def FindFileByName(self, name):
return self._files[name]
db = SimpleDescriptorDB({f1.name: f1, f2.name: f2, f3.name: f3})
pool = descriptor_pool.DescriptorPool(db)
pool = descriptor_pool.Default()
try:
pool.Add(f1)
pool.Add(f2)
pool.Add(f3)
except:
pass
msgs = message_factory.GetMessageClassesForFiles(
[f1.name, f3.name], pool) # Deliberately not f2.
msg = msgs['google.protobuf.python.internal.Container']
@ -278,11 +275,24 @@ class MessageFactoryTest(unittest.TestCase):
m.Extensions[ext2].setting = 345
serialized = m.SerializeToString()
pool = descriptor_pool.DescriptorPool(db)
f1.name='google/protobuf/internal/another/container.proto'
f1.package='google.protobuf.python.internal.another'
f2.name='google/protobuf/internal/another/value_type.proto'
f2.package='google.protobuf.python.internal.another'
f3.name='google/protobuf/internal/another/extension.proto'
f3.package='google.protobuf.python.internal.another'
f3.ClearField('dependency')
f3.dependency.extend([f1.name, f2.name])
try:
pool.Add(f1)
pool.Add(f2)
pool.Add(f3)
except:
pass
msgs = message_factory.GetMessageClassesForFiles(
[f1.name, f3.name], pool) # Deliberately not f2.
msg = msgs['google.protobuf.python.internal.Container']
desc = msgs['google.protobuf.python.internal.Extension'].DESCRIPTOR
msg = msgs['google.protobuf.python.internal.another.Container']
desc = msgs['google.protobuf.python.internal.another.Extension'].DESCRIPTOR
ext1 = desc.file.extensions_by_name['top_level_extension_field']
ext2 = desc.extensions_by_name['nested_extension_field']
m = msg.FromString(serialized)

Loading…
Cancel
Save