Skip to content

Commit 6ef3745

Browse files
yoneyfacebook-github-bot
authored andcommitted
Add struct evolution test
Summary: Add struct evolution test that already implemented for C++ Reviewed By: Filip-F Differential Revision: D59643661 fbshipit-source-id: f78a1c6a2494dfae82ff9281b735604458543ef5
1 parent 0ab306f commit 6ef3745

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

thrift/test/SchemaEvolutionTest.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ TYPED_TEST(EvolutionTest, evolution) {
5757
EXPECT_EQ(newObj.required_to_optional(), *oldObj.required_to_optional());
5858
EXPECT_EQ(newObj.required_to_required(), *oldObj.required_to_required());
5959

60+
// SimpleJSON: This protocol doesn't output verbose field types and uses field
61+
// names instead of IDs (which affects schema evolution).
6062
if (std::is_same_v<Serializer, SimpleJSONSerializer>) {
6163
EXPECT_EQ(newObj.unqualified_new(), "");
6264
EXPECT_EQ(newObj.required_new(), "");

thrift/test/thrift-python/schema_evolution_test.py

+65-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,75 @@
2121
MyStruct_V2,
2222
MyUnion_V1,
2323
MyUnion_V2,
24+
New,
25+
Old,
2426
)
2527
from thrift.python.protocol import Protocol
2628

2729
from thrift.python.serializer import deserialize, serialize
28-
from thrift.python.types import StructOrUnion
30+
from thrift.python.types import isset, StructOrUnion
31+
32+
33+
@parameterized_class(
34+
("protocol"),
35+
[(Protocol.BINARY,), (Protocol.COMPACT,), (Protocol.JSON,)],
36+
)
37+
class TestEvolution(unittest.TestCase):
38+
def test_evolution(self) -> None:
39+
params = {field_name: field_name for field_name, _ in Old}
40+
old_struct = Old(**params)
41+
serialized = serialize(old_struct, protocol=self.protocol)
42+
new_struct = deserialize(New, serialized, protocol=self.protocol)
43+
44+
self.assertEqual(
45+
old_struct.unqualified_to_unqualified, new_struct.unqualified_to_unqualified
46+
)
47+
self.assertEqual(
48+
old_struct.unqualified_to_optional, new_struct.unqualified_to_optional
49+
)
50+
self.assertEqual(
51+
old_struct.unqualified_to_required, new_struct.unqualified_to_required
52+
)
53+
54+
self.assertEqual(
55+
old_struct.optional_to_unqualified, new_struct.optional_to_unqualified
56+
)
57+
self.assertEqual(
58+
old_struct.optional_to_optional, new_struct.optional_to_optional
59+
)
60+
self.assertEqual(
61+
old_struct.optional_to_required, new_struct.optional_to_required
62+
)
63+
64+
self.assertEqual(
65+
old_struct.required_to_unqualified, new_struct.required_to_unqualified
66+
)
67+
self.assertEqual(
68+
old_struct.required_to_optional, new_struct.required_to_optional
69+
)
70+
self.assertEqual(
71+
old_struct.required_to_required, new_struct.required_to_required
72+
)
73+
74+
# Protocol.JSON is SimpleJSON
75+
if self.protocol is Protocol.JSON:
76+
self.assertEqual(new_struct.unqualified_new, "")
77+
self.assertEqual(new_struct.required_new, "")
78+
79+
self.assertFalse(isset(new_struct)["unqualified_new"])
80+
self.assertIsNone(new_struct.optional_new)
81+
self.assertIsNotNone(new_struct.required_new)
82+
else:
83+
self.assertEqual(new_struct.unqualified_new, old_struct.unqualified_old)
84+
self.assertEqual(new_struct.optional_new, old_struct.optional_old)
85+
self.assertEqual(new_struct.required_new, old_struct.required_old)
86+
87+
self.assertEqual(new_struct.unqualified_added, "")
88+
self.assertEqual(new_struct.required_added, "")
89+
90+
self.assertFalse(isset(new_struct)["unqualified_added"])
91+
self.assertIsNone(new_struct.optional_added)
92+
self.assertIsNotNone(new_struct.required_added)
2993

3094

3195
@parameterized_class(

0 commit comments

Comments
 (0)