@@ -26,6 +26,7 @@ import (
26
26
"github.com/coder/coder/v2/coderd"
27
27
"github.com/coder/coder/v2/coderd/coderdtest"
28
28
"github.com/coder/coder/v2/coderd/database"
29
+ "github.com/coder/coder/v2/coderd/database/dbauthz"
29
30
"github.com/coder/coder/v2/coderd/database/dbfake"
30
31
"github.com/coder/coder/v2/coderd/database/dbmem"
31
32
"github.com/coder/coder/v2/coderd/database/dbtime"
@@ -876,6 +877,62 @@ func TestWorkspaceAgentReportStats(t *testing.T) {
876
877
"%s is not after %s" , newWorkspace .LastUsedAt , r .Workspace .LastUsedAt ,
877
878
)
878
879
})
880
+
881
+ t .Run ("FailDeleted" , func (t * testing.T ) {
882
+ t .Parallel ()
883
+
884
+ client , db := coderdtest .NewWithDatabase (t , nil )
885
+ user := coderdtest .CreateFirstUser (t , client )
886
+ r := dbfake .WorkspaceBuild (t , db , database.Workspace {
887
+ OrganizationID : user .OrganizationID ,
888
+ OwnerID : user .UserID ,
889
+ }).WithAgent ().Do ()
890
+
891
+ agentClient := agentsdk .New (client .URL )
892
+ agentClient .SetSessionToken (r .AgentToken )
893
+
894
+ _ , err := agentClient .PostStats (context .Background (), & agentsdk.Stats {
895
+ ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
896
+ // Set connection count to 1 but all session counts to zero to
897
+ // assert we aren't updating last_used_at for a connections that may
898
+ // be spawned passively by the dashboard.
899
+ ConnectionCount : 1 ,
900
+ RxPackets : 1 ,
901
+ RxBytes : 1 ,
902
+ TxPackets : 1 ,
903
+ TxBytes : 1 ,
904
+ SessionCountVSCode : 0 ,
905
+ SessionCountJetBrains : 0 ,
906
+ SessionCountReconnectingPTY : 0 ,
907
+ SessionCountSSH : 0 ,
908
+ ConnectionMedianLatencyMS : 10 ,
909
+ })
910
+ require .NoError (t , err )
911
+
912
+ newWorkspace , err := client .Workspace (context .Background (), r .Workspace .ID )
913
+ require .NoError (t , err )
914
+
915
+ err = db .UpdateWorkspaceDeletedByID (dbauthz .AsSystemRestricted (context .Background ()), database.UpdateWorkspaceDeletedByIDParams {
916
+ ID : newWorkspace .ID ,
917
+ Deleted : true ,
918
+ })
919
+ require .NoError (t , err )
920
+
921
+ _ , err = agentClient .PostStats (context .Background (), & agentsdk.Stats {
922
+ ConnectionsByProto : map [string ]int64 {"TCP" : 1 },
923
+ ConnectionCount : 1 ,
924
+ RxPackets : 1 ,
925
+ RxBytes : 1 ,
926
+ TxPackets : 1 ,
927
+ TxBytes : 1 ,
928
+ SessionCountVSCode : 1 ,
929
+ SessionCountJetBrains : 0 ,
930
+ SessionCountReconnectingPTY : 0 ,
931
+ SessionCountSSH : 0 ,
932
+ ConnectionMedianLatencyMS : 10 ,
933
+ })
934
+ require .ErrorContains (t , err , "Workspace has been deleted." )
935
+ })
879
936
}
880
937
881
938
func TestWorkspaceAgent_LifecycleState (t * testing.T ) {
0 commit comments