@@ -311,6 +311,7 @@ func TestFirstStatusReport(t *testing.T) {
311
311
// Start a Server.
312
312
srv := internal .StartMockServer (t )
313
313
srv .OnMessage = func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
314
+ assert .EqualValues (t , 0 , msg .SequenceNum )
314
315
return & protobufs.ServerToAgent {
315
316
InstanceUid : msg .InstanceUid ,
316
317
RemoteConfig : remoteConfig ,
@@ -353,8 +354,13 @@ func TestFirstStatusReport(t *testing.T) {
353
354
func TestIncludesDetailsOnReconnect (t * testing.T ) {
354
355
srv := internal .StartMockServer (t )
355
356
357
+ seqNum := 0
358
+
356
359
var receivedDetails int64
357
360
srv .OnMessage = func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
361
+ assert .EqualValues (t , seqNum , msg .SequenceNum )
362
+ seqNum ++
363
+
358
364
// Track when we receive AgentDescription
359
365
if msg .AgentDescription != nil {
360
366
atomic .AddInt64 (& receivedDetails , 1 )
@@ -687,6 +693,7 @@ func TestReportAgentDescription(t *testing.T) {
687
693
688
694
// ---> Server
689
695
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
696
+ assert .EqualValues (t , 0 , msg .SequenceNum )
690
697
// The first status report after Start must have full AgentDescription.
691
698
assert .True (t , proto .Equal (client .AgentDescription (), msg .AgentDescription ))
692
699
return & protobufs.ServerToAgent {InstanceUid : msg .InstanceUid }
@@ -699,25 +706,22 @@ func TestReportAgentDescription(t *testing.T) {
699
706
// ---> Server
700
707
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
701
708
// The status report must have compressed AgentDescription.
702
- descr := msg .AgentDescription
703
- assert .Nil (t , descr .IdentifyingAttributes )
704
- assert .Nil (t , descr .NonIdentifyingAttributes )
709
+ assert .Nil (t , msg .AgentDescription )
705
710
706
- // The Hash field must be present and unchanged.
707
- assert .NotNil (t , descr .Hash )
708
- assert .EqualValues (t , client .AgentDescription ().Hash , descr .Hash )
711
+ assert .EqualValues (t , 1 , msg .SequenceNum )
709
712
710
713
// Ask client for full AgentDescription.
711
714
return & protobufs.ServerToAgent {
712
715
InstanceUid : msg .InstanceUid ,
713
- Flags : protobufs .ServerToAgent_ReportAgentDescription ,
716
+ Flags : protobufs .ServerToAgent_ReportFullState ,
714
717
}
715
718
})
716
719
717
720
// Server has requested the client to report, so there will be another message
718
721
// coming to the Server.
719
722
// ---> Server
720
723
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
724
+ assert .EqualValues (t , 2 , msg .SequenceNum )
721
725
// The status report must again have full AgentDescription
722
726
// because the Server asked for it.
723
727
assert .True (t , proto .Equal (client .AgentDescription (), msg .AgentDescription ))
@@ -758,6 +762,7 @@ func TestReportEffectiveConfig(t *testing.T) {
758
762
759
763
// ---> Server
760
764
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
765
+ assert .EqualValues (t , 0 , msg .SequenceNum )
761
766
// The first status report after Start must have full EffectiveConfig.
762
767
assert .True (t , proto .Equal (clientEffectiveConfig , msg .EffectiveConfig ))
763
768
return & protobufs.ServerToAgent {InstanceUid : msg .InstanceUid }
@@ -770,23 +775,21 @@ func TestReportEffectiveConfig(t *testing.T) {
770
775
// ---> Server
771
776
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
772
777
// The status report must have compressed EffectiveConfig.
773
- cfg := msg .EffectiveConfig
774
- assert .Nil (t , cfg .ConfigMap )
778
+ assert .Nil (t , msg .EffectiveConfig )
775
779
776
- // Hash must be present and unchanged.
777
- assert .NotNil (t , cfg .Hash )
778
- assert .EqualValues (t , clientEffectiveConfig .Hash , cfg .Hash )
780
+ assert .EqualValues (t , 1 , msg .SequenceNum )
779
781
780
782
// Ask client for full AgentDescription.
781
783
return & protobufs.ServerToAgent {
782
784
InstanceUid : msg .InstanceUid ,
783
- Flags : protobufs .ServerToAgent_ReportEffectiveConfig ,
785
+ Flags : protobufs .ServerToAgent_ReportFullState ,
784
786
}
785
787
})
786
788
787
789
// Server has requested the client to report, so there will be another message.
788
790
// ---> Server
789
791
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
792
+ assert .EqualValues (t , 2 , msg .SequenceNum )
790
793
// The status report must again have full EffectiveConfig
791
794
// because Server asked for it.
792
795
assert .True (t , proto .Equal (clientEffectiveConfig , msg .EffectiveConfig ))
@@ -841,6 +844,7 @@ func verifyRemoteConfigUpdate(t *testing.T, successCase bool, expectStatus *prot
841
844
remoteCfg := createRemoteConfig ()
842
845
// ---> Server
843
846
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
847
+ assert .EqualValues (t , 0 , msg .SequenceNum )
844
848
// Send the remote config to the Agent.
845
849
return & protobufs.ServerToAgent {
846
850
InstanceUid : msg .InstanceUid ,
@@ -855,12 +859,12 @@ func verifyRemoteConfigUpdate(t *testing.T, successCase bool, expectStatus *prot
855
859
856
860
// ---> Server
857
861
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
862
+ assert .EqualValues (t , 1 , msg .SequenceNum )
858
863
// Verify that the remote config status is as expected.
859
864
status := msg .RemoteConfigStatus
860
865
assert .EqualValues (t , expectStatus .Status , status .Status )
861
866
assert .Equal (t , expectStatus .ErrorMessage , status .ErrorMessage )
862
867
assert .EqualValues (t , remoteCfg .ConfigHash , status .LastRemoteConfigHash )
863
- assert .NotNil (t , status .Hash )
864
868
865
869
firstConfigStatus = proto .Clone (status ).(* protobufs.RemoteConfigStatus )
866
870
@@ -873,24 +877,21 @@ func verifyRemoteConfigUpdate(t *testing.T, successCase bool, expectStatus *prot
873
877
874
878
// ---> Server
875
879
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
876
- // This time all fields except Hash must be unset. This is expected
880
+ // This time the RemoteConfigStatus field must be unset. This is expected
877
881
// as compression in OpAMP.
878
- status := msg .RemoteConfigStatus
879
- require .NotNil (t , status )
880
- assert .EqualValues (t , firstConfigStatus .Hash , status .Hash )
881
- assert .EqualValues (t , protobufs .RemoteConfigStatus_UNSET , status .Status )
882
- assert .EqualValues (t , "" , status .ErrorMessage )
883
- assert .Nil (t , status .LastRemoteConfigHash )
882
+ require .Nil (t , msg .RemoteConfigStatus )
883
+ assert .EqualValues (t , 2 , msg .SequenceNum )
884
884
885
885
return & protobufs.ServerToAgent {
886
886
InstanceUid : msg .InstanceUid ,
887
887
// Ask client to report full status.
888
- Flags : protobufs .ServerToAgent_ReportRemoteConfigStatus ,
888
+ Flags : protobufs .ServerToAgent_ReportFullState ,
889
889
}
890
890
})
891
891
892
892
// ---> Server
893
893
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
894
+ assert .EqualValues (t , 3 , msg .SequenceNum )
894
895
// Exact same full status must be present again.
895
896
status := msg .RemoteConfigStatus
896
897
assert .True (t , proto .Equal (status , firstConfigStatus ))
@@ -992,6 +993,7 @@ func verifyUpdatePackages(t *testing.T, testCase packageTestCase) {
992
993
993
994
// ---> Server
994
995
srv .Expect (func (msg * protobufs.AgentToServer ) * protobufs.ServerToAgent {
996
+ assert .EqualValues (t , 0 , msg .SequenceNum )
995
997
// Send the packages to the Agent.
996
998
return & protobufs.ServerToAgent {
997
999
InstanceUid : msg .InstanceUid ,
@@ -1002,8 +1004,6 @@ func verifyUpdatePackages(t *testing.T, testCase packageTestCase) {
1002
1004
// The Agent will try to install the packages and will send the status
1003
1005
// report about it back to the Server.
1004
1006
1005
- var lastStatusHash []byte
1006
-
1007
1007
// ---> Server
1008
1008
// Wait for the expected package statuses to be received.
1009
1009
srv .EventuallyExpect ("full PackageStatuses" ,
@@ -1013,7 +1013,6 @@ func verifyUpdatePackages(t *testing.T, testCase packageTestCase) {
1013
1013
status := msg .PackageStatuses
1014
1014
require .NotNil (t , status )
1015
1015
assert .EqualValues (t , testCase .expectedStatus .ServerProvidedAllPackagesHash , status .ServerProvidedAllPackagesHash )
1016
- lastStatusHash = status .Hash
1017
1016
1018
1017
if testCase .expectedError != "" {
1019
1018
assert .EqualValues (t , testCase .expectedError , status .ErrorMessage )
@@ -1046,7 +1045,6 @@ func verifyUpdatePackages(t *testing.T, testCase packageTestCase) {
1046
1045
assert .Len (t , status .Packages , len (testCase .available .Packages ))
1047
1046
}
1048
1047
}
1049
- assert .NotNil (t , status .Hash )
1050
1048
1051
1049
return & protobufs.ServerToAgent {InstanceUid : msg .InstanceUid }, expectedStatusReceived
1052
1050
})
@@ -1069,21 +1067,13 @@ func verifyUpdatePackages(t *testing.T, testCase packageTestCase) {
1069
1067
srv .EventuallyExpect ("compressed PackageStatuses" ,
1070
1068
func (msg * protobufs.AgentToServer ) (* protobufs.ServerToAgent , bool ) {
1071
1069
// Ensure that compressed status is received.
1072
- status := msg .PackageStatuses
1073
- require .NotNil (t , status )
1074
- compressedReceived := status .ServerProvidedAllPackagesHash == nil
1075
- if compressedReceived {
1076
- assert .Nil (t , status .ServerProvidedAllPackagesHash )
1077
- assert .Nil (t , status .Packages )
1078
- }
1079
- assert .NotNil (t , status .Hash )
1080
- assert .Equal (t , lastStatusHash , status .Hash )
1070
+ compressedReceived := msg .PackageStatuses == nil
1081
1071
1082
1072
response := & protobufs.ServerToAgent {InstanceUid : msg .InstanceUid }
1083
1073
1084
1074
if compressedReceived {
1085
1075
// Ask for full report again.
1086
- response .Flags = protobufs .ServerToAgent_ReportPackageStatuses
1076
+ response .Flags = protobufs .ServerToAgent_ReportFullState
1087
1077
} else {
1088
1078
// Keep triggering status report by setting AgentDescription
1089
1079
// until the compressed PackageStatuses arrives.
@@ -1114,8 +1104,7 @@ func createDownloadSrv(t *testing.T) *httptest.Server {
1114
1104
w .WriteHeader (http .StatusOK )
1115
1105
_ , err := w .Write (packageFileContent )
1116
1106
assert .NoError (t , err )
1117
- },
1118
- )
1107
+ })
1119
1108
1120
1109
srv := httptest .NewServer (m )
1121
1110
0 commit comments