more tests (#1832)

Co-authored-by: stas <statis@microsoft.com>
This commit is contained in:
Stas
2022-04-22 13:00:57 -07:00
committed by GitHub
parent 812a6d7517
commit ddc415c91e
5 changed files with 113 additions and 47 deletions

View File

@ -207,20 +207,20 @@ public record EventProxyCreated(
) : BaseEvent(); ) : BaseEvent();
record EventProxyDeleted( public record EventProxyDeleted(
Region Region, Region Region,
Guid? ProxyId Guid? ProxyId
) : BaseEvent(); ) : BaseEvent();
record EventProxyFailed( public record EventProxyFailed(
Region Region, Region Region,
Guid? ProxyId, Guid? ProxyId,
Error Error Error Error
) : BaseEvent(); ) : BaseEvent();
record EventProxyStateUpdated( public record EventProxyStateUpdated(
Region Region, Region Region,
Guid ProxyId, Guid ProxyId,
VmState State VmState State
@ -262,14 +262,14 @@ public record EventNodeHeartbeat(
// NodeState state // NodeState state
// ) : BaseEvent(); // ) : BaseEvent();
record EventCrashReported( public record EventCrashReported(
Report Report, Report Report,
Container Container, Container Container,
[property: JsonPropertyName("filename")] String FileName, [property: JsonPropertyName("filename")] String FileName,
TaskConfig? TaskConfig TaskConfig? TaskConfig
) : BaseEvent(); ) : BaseEvent();
record EventRegressionReported( public record EventRegressionReported(
RegressionReport RegressionReport, RegressionReport RegressionReport,
Container Container, Container Container,
[property: JsonPropertyName("filename")] String FileName, [property: JsonPropertyName("filename")] String FileName,
@ -277,7 +277,7 @@ record EventRegressionReported(
) : BaseEvent(); ) : BaseEvent();
record EventFileAdded( public record EventFileAdded(
Container Container, Container Container,
[property: JsonPropertyName("filename")] String FileName [property: JsonPropertyName("filename")] String FileName
) : BaseEvent(); ) : BaseEvent();

View File

@ -419,7 +419,6 @@ public class ContainerConverter : JsonConverter<Container>
} }
public record Notification( public record Notification(
DateTime? Timestamp,
Container Container, Container Container,
Guid NotificationId, Guid NotificationId,
NotificationTemplate Config NotificationTemplate Config

View File

@ -22,11 +22,11 @@ public record WebhookMessageEventGrid(
[property: JsonPropertyName("dataVersion")] string DataVersion, [property: JsonPropertyName("dataVersion")] string DataVersion,
string Subject, string Subject,
[property: JsonPropertyName("EventType")] EventType EventType, [property: JsonPropertyName("EventType")] EventType EventType,
[property: JsonPropertyName("eventTime")] DateTimeOffset eventTime, [property: JsonPropertyName("eventTime")] DateTimeOffset EventTime,
Guid Id, Guid Id,
[property: TypeDiscrimnatorAttribute("EventType", typeof(EventTypeProvider))] [property: TypeDiscrimnatorAttribute("EventType", typeof(EventTypeProvider))]
[property: JsonConverter(typeof(BaseEventConverter))] [property: JsonConverter(typeof(BaseEventConverter))]
BaseEvent data); BaseEvent Data);
// TODO: This should inherit from Entity Base ? no, since there is // TODO: This should inherit from Entity Base ? no, since there is

View File

@ -258,7 +258,7 @@ public class EntityConverter
{ {
return entity.GetDateTimeOffset(fieldName); return entity.GetDateTimeOffset(fieldName);
} }
else if (ef.type == typeof(DateTime)) else if (ef.type == typeof(DateTime) || ef.type == typeof(DateTime?))
{ {
return entity.GetDateTime(fieldName); return entity.GetDateTime(fieldName);
} }

View File

@ -14,27 +14,22 @@ namespace Tests
public class OrmGenerators public class OrmGenerators
{ {
public static Gen<BaseEvent> BaseEvent() public static Gen<BaseEvent> BaseEvent()
{ {
return Gen.OneOf(new[] { return Gen.OneOf(new[] {
Arb.Generate<EventNodeHeartbeat>().Select(e => e as BaseEvent), Arb.Generate<EventNodeHeartbeat>().Select(e => e as BaseEvent),
Arb.Generate<EventTaskHeartbeat>().Select(e => e as BaseEvent), Arb.Generate<EventTaskHeartbeat>().Select(e => e as BaseEvent),
Arb.Generate<EventInstanceConfigUpdated>().Select(e => e as BaseEvent) Arb.Generate<EventInstanceConfigUpdated>().Select(e => e as BaseEvent),
Arb.Generate<EventProxyCreated>().Select(e => e as BaseEvent),
Arb.Generate<EventProxyDeleted>().Select(e => e as BaseEvent),
Arb.Generate<EventProxyFailed>().Select(e => e as BaseEvent),
Arb.Generate<EventProxyStateUpdated>().Select(e => e as BaseEvent),
Arb.Generate<EventCrashReported>().Select(e => e as BaseEvent),
Arb.Generate<EventRegressionReported>().Select(e => e as BaseEvent),
Arb.Generate<EventFileAdded>().Select(e => e as BaseEvent),
}); });
} }
public static Gen<EventType> EventType()
{
return Gen.OneOf(new[] {
Gen.Constant(Microsoft.OneFuzz.Service.EventType.NodeHeartbeat),
Gen.Constant(Microsoft.OneFuzz.Service.EventType.TaskHeartbeat),
Gen.Constant(Microsoft.OneFuzz.Service.EventType.InstanceConfigUpdated)
});
}
public static Gen<Uri> Uri() public static Gen<Uri> Uri()
{ {
return Arb.Generate<IPv4Address>().Select( return Arb.Generate<IPv4Address>().Select(
@ -44,14 +39,14 @@ namespace Tests
public static Gen<WebhookMessageLog> WebhookMessageLog() public static Gen<WebhookMessageLog> WebhookMessageLog()
{ {
return Arb.Generate<Tuple<Tuple<Guid, EventType, BaseEvent, Guid, string, Guid>, Tuple<WebhookMessageState, int>>>().Select( return Arb.Generate<Tuple<Tuple<Guid, BaseEvent, Guid, string, Guid>, Tuple<WebhookMessageState, int>>>().Select(
arg => new WebhookMessageLog( arg => new WebhookMessageLog(
EventId: arg.Item1.Item1, EventId: arg.Item1.Item1,
EventType: arg.Item1.Item2, EventType: arg.Item1.Item2.GetEventType(),
Event: arg.Item1.Item3, Event: arg.Item1.Item2,
InstanceId: arg.Item1.Item4, InstanceId: arg.Item1.Item3,
InstanceName: arg.Item1.Item5, InstanceName: arg.Item1.Item4,
WebhookId: arg.Item1.Item6, WebhookId: arg.Item1.Item5,
State: arg.Item2.Item1, State: arg.Item2.Item1,
TryCount: arg.Item2.Item2 TryCount: arg.Item2.Item2
)); ));
@ -187,8 +182,6 @@ namespace Tests
) )
); );
} }
public static Gen<Scaleset> Scaleset() public static Gen<Scaleset> Scaleset()
{ {
return Arb.Generate<Tuple< return Arb.Generate<Tuple<
@ -232,25 +225,41 @@ namespace Tests
MessageFormat: arg.Item6 MessageFormat: arg.Item6
) )
); );
} }
public static Gen<WebhookMessage> WebhookMessage() public static Gen<WebhookMessage> WebhookMessage()
{ {
return Arb.Generate<Tuple<Guid, EventType, BaseEvent, Guid, string, Guid>>().Select( return Arb.Generate<Tuple<Guid, BaseEvent, Guid, string, Guid>>().Select(
arg => arg =>
new WebhookMessage( new WebhookMessage(
EventId: arg.Item1, EventId: arg.Item1,
EventType: arg.Item2, EventType: arg.Item2.GetEventType(),
Event: arg.Item3, Event: arg.Item2,
InstanceId: arg.Item4, InstanceId: arg.Item3,
InstanceName: arg.Item5, InstanceName: arg.Item4,
WebhookId: arg.Item6 WebhookId: arg.Item5
) )
); ); ;
} }
public static Gen<WebhookMessageEventGrid> WebhookMessageEventGrid()
{
return Arb.Generate<Tuple<string, string, BaseEvent, Guid, DateTimeOffset>>().Select(
arg =>
new WebhookMessageEventGrid(
DataVersion: arg.Item1,
Subject: arg.Item2,
EventType: arg.Item3.GetEventType(),
Data: arg.Item3,
Id: arg.Item4,
EventTime: arg.Item5
)
); ;
}
public static Gen<Report> Report() public static Gen<Report> Report()
{ {
return Arb.Generate<Tuple<string, BlobRef, List<string>, Guid, int>>().Select( return Arb.Generate<Tuple<string, BlobRef, List<string>, Guid, int>>().Select(
@ -285,6 +294,18 @@ namespace Tests
arg => new Container(string.Join("", arg.Item1.Get.Where(c => char.IsLetterOrDigit(c) || c == '-'))!) arg => new Container(string.Join("", arg.Item1.Get.Where(c => char.IsLetterOrDigit(c) || c == '-'))!)
); );
} }
public static Gen<Notification> Notification()
{
return Arb.Generate<Tuple<Container, Guid, NotificationTemplate>>().Select(
arg => new Notification(
Container: arg.Item1,
NotificationId: arg.Item2,
Config: arg.Item3
)
);
}
} }
public class OrmArb public class OrmArb
@ -299,11 +320,6 @@ namespace Tests
return Arb.From(OrmGenerators.BaseEvent()); return Arb.From(OrmGenerators.BaseEvent());
} }
public static Arbitrary<EventType> EventType()
{
return Arb.From(OrmGenerators.EventType());
}
public static Arbitrary<Node> Node() public static Arbitrary<Node> Node()
{ {
return Arb.From(OrmGenerators.Node()); return Arb.From(OrmGenerators.Node());
@ -373,6 +389,16 @@ namespace Tests
{ {
return Arb.From(OrmGenerators.Container()); return Arb.From(OrmGenerators.Container());
} }
public static Arbitrary<Notification> Notification()
{
return Arb.From(OrmGenerators.Notification());
}
public static Arbitrary<WebhookMessageEventGrid> WebhookMessageEventGrid()
{
return Arb.From(OrmGenerators.WebhookMessageEventGrid());
}
} }
@ -555,14 +581,18 @@ namespace Tests
return Test(log); return Test(log);
} }
[Property] [Property]
public bool Webhook(Webhook wh) public bool Webhook(Webhook wh)
{ {
return Test(wh); return Test(wh);
} }
[Property]
public bool Notification(Notification n)
{
return Test(n);
}
//Sample function on how repro a failing test run, using Replay //Sample function on how repro a failing test run, using Replay
@ -782,6 +812,43 @@ namespace Tests
{ {
return Test(e); return Test(e);
} }
[Property]
public bool Notification(Notification e)
{
return Test(e);
}
[Property]
public bool NoReproReport(NoReproReport e)
{
return Test(e);
}
[Property]
public bool CrashTestResult(CrashTestResult e)
{
return Test(e);
}
[Property]
public bool NotificationTemplate(NotificationTemplate e)
{
return Test(e);
}
/*
//Sample function on how repro a failing test run, using Replay
//functionality of FsCheck. Feel free to
[Property]
void Replay()
{
var seed = FsCheck.Random.StdGen.NewStdGen(4570702, 297027754);
var p = Prop.ForAll((WebhookMessageEventGrid x) => WebhookMessageEventGrid(x) );
p.Check(new Configuration { Replay = seed });
}
*/
} }
} }