Skip to content

Commit f8217be

Browse files
committed
added a few tests to isolate CI failure; use HasSingle for DisableContextualSerializer
1 parent f1a0493 commit f8217be

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/protobuf-net.Grpc/Configuration/ProtoBufMarshallerFactory.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,24 @@ internal ProtoBufMarshallerFactory(TypeModel model, Options options, object? use
7474
_ => new SerializationContext { Context = userState }
7575
};
7676

77-
if (UseContextualSerializer)
77+
if (!HasSingle(Options.DisableContextualSerializer))
7878
{
7979
// test these once rather than every time
8080
_measuredWriterModel = model as IMeasuredProtoOutput<IBufferWriter<byte>>;
8181
_squenceReaderModel = model as IProtoInput<ReadOnlySequence<byte>>;
8282
}
8383
}
8484

85-
private bool UseContextualSerializer => (_options & Options.DisableContextualSerializer) == 0;
86-
8785
[MethodImpl(MethodImplOptions.AggressiveInlining)]
88-
private bool Has(Options option) => (_options & option) == option;
86+
private bool HasSingle(Options option) => (_options & option) != 0;
8987

9088
/// <summary>
9189
/// Deserializes an object from a payload
9290
/// </summary>
9391
protected internal override global::Grpc.Core.Marshaller<T> CreateMarshaller<T>()
94-
=> UseContextualSerializer
95-
? new global::Grpc.Core.Marshaller<T>(ContextualSerialize<T>, ContextualDeserialize<T>)
96-
: base.CreateMarshaller<T>();
92+
=> HasSingle(Options.DisableContextualSerializer)
93+
? base.CreateMarshaller<T>()
94+
: new global::Grpc.Core.Marshaller<T>(ContextualSerialize<T>, ContextualDeserialize<T>);
9795

9896
#if DEBUG
9997
private int _uplevelBufferReadCount, _uplevelBufferWriteCount;
@@ -179,7 +177,7 @@ private T ContextualDeserialize<T>(global::Grpc.Core.DeserializationContext cont
179177
/// Indicates whether a type should be considered as a serializable data type
180178
/// </summary>
181179
protected internal override bool CanSerialize(Type type)
182-
=> Has(Options.ContractTypesOnly)
180+
=> HasSingle(Options.ContractTypesOnly)
183181
? _model.CanSerializeContractType(type)
184182
: _model.CanSerialize(type);
185183

tests/protobuf-net.Grpc.Test.Integration/StreamTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using ProtoBuf.Grpc.Client;
55
using ProtoBuf.Grpc.Configuration;
66
using ProtoBuf.Grpc.Server;
7+
using ProtoBuf.Meta;
78
using System;
89
using System.Collections.Generic;
910
using System.Linq;
@@ -358,6 +359,16 @@ public StreamTests(int port, StreamTestsFixture fixture, ITestOutputHelper log)
358359
protected abstract IAsyncDisposable CreateClient(out IStreamAPI client);
359360

360361
const int DEFAULT_SIZE = 20;
362+
363+
[Fact]
364+
public void FooIsContractType()
365+
=> Assert.True(RuntimeTypeModel.Default.IsDefined(typeof(Foo)));
366+
367+
368+
[Fact]
369+
public void FooHasMarshaller()
370+
=> Assert.NotNull(BinderConfiguration.Default.GetMarshaller<Foo>());
371+
361372
[Theory]
362373
[InlineData(Scenario.RunToCompletion, DEFAULT_SIZE, CallContextFlags.None)]
363374
[InlineData(Scenario.RunToCompletion, DEFAULT_SIZE, CallContextFlags.CaptureMetadata)]

0 commit comments

Comments
 (0)