MCPcopy Index your code
hub / github.com/cockroachdb/errors / TestSimultaneousMigration

Function TestSimultaneousMigration

errbase/migrations_test.go:138–169  ·  view source on GitHub ↗

Scenario 2: simultaneous migration - vA renames foo -> bar vA calls RegisterTypeMigration("foo", (*bar)(nil)) - vB renames foo -> qux vB calls RegisterTypeMigration("foo", (*qux)(nil)) - vA and vB are connected - vA sends an error to vB: - vA translates the error key upon send from bar to foo's key

(t *testing.T)

Source from the content-addressed store, hash-verified

136// - vA translates the error key upon send from bar to foo's key
137// - vB recognizes that "foo" refers to qux
138func TestSimultaneousMigration(t *testing.T) {
139 // == Scenario on vA ==
140 defer errbase.TestingWithEmptyMigrationRegistry()()
141 origErr := barErr{}
142 // Register the fact that foo was migrated to bar.
143 errbase.RegisterTypeMigration(myPkgPath, "errbase_test.fooErr", origErr)
144 // Send the error to vB.
145 enc := errbase.EncodeError(context.Background(), origErr)
146 // Clean up the decoder, so that type becomes unknown for further tests.
147 errbase.RegisterLeafDecoder(errbase.GetTypeKey(origErr), nil)
148 // Erase the migration we have set up above, so that the test
149 // underneath does not know about it.
150 defer errbase.TestingWithEmptyMigrationRegistry()()
151
152 // == Scenario on v2 ==
153 defer errbase.TestingWithEmptyMigrationRegistry()()
154 // Register the fact that foo was migrated to qux.
155 errbase.RegisterTypeMigration(myPkgPath, "errbase_test.fooErr", quxErr{})
156 // Register the qux decoder.
157 errbase.RegisterLeafDecoder(errbase.GetTypeKey(quxErr{}),
158 func(_ context.Context, _ string, _ []string, _ proto.Message) error { return quxErr{} })
159 // Receive the error from vA.
160 dec := errbase.DecodeError(context.Background(), enc)
161 // Clean up, so that type qux becomes unknown for further tests.
162 errbase.RegisterLeafDecoder(errbase.GetTypeKey(quxErr{}), nil)
163
164 // Main test: check that vA normalized the bar error to foo,
165 // and v2 instantiated it as qux.
166 if _, ok := dec.(quxErr); !ok {
167 t.Errorf("migration failed; expected type quxErr, got %T", dec)
168 }
169}
170
171// Scenario 3: migrated error passing through
172// - v2 renames foo -> bar

Callers

nothing calls this directly

Calls 6

RegisterTypeMigrationFunction · 0.92
EncodeErrorFunction · 0.92
RegisterLeafDecoderFunction · 0.92
GetTypeKeyFunction · 0.92
DecodeErrorFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…