V0.6.1 Arroyo Toad
This commit is contained in:
parent
5d5cc7ef0a
commit
0c294045dc
@ -26,7 +26,7 @@ public actor IoTSimulatorCore {
|
|||||||
|
|
||||||
// schedule work
|
// schedule work
|
||||||
let task = IoTSimulatorCore.schedule(envID: environment.location, deviceID: device.deviceID) { msg in
|
let task = IoTSimulatorCore.schedule(envID: environment.location, deviceID: device.deviceID) { msg in
|
||||||
print("\(msg.description)\n\n")
|
//print("\(msg.description)\n\n")
|
||||||
} failure: {
|
} failure: {
|
||||||
print("Something is wrong")
|
print("Something is wrong")
|
||||||
}
|
}
|
||||||
@ -47,6 +47,12 @@ public actor IoTSimulatorCore {
|
|||||||
return IoTSimulatorCore.devices[devID]
|
return IoTSimulatorCore.devices[devID]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func nukeAll() {
|
||||||
|
for value in IoTSimulatorCore.dev_tasks {
|
||||||
|
value.value.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static func schedule(
|
private static func schedule(
|
||||||
envID: sending String,
|
envID: sending String,
|
||||||
deviceID: sending String,
|
deviceID: sending String,
|
||||||
@ -55,18 +61,32 @@ public actor IoTSimulatorCore {
|
|||||||
) -> Task<(), Never> {
|
) -> Task<(), Never> {
|
||||||
return Task {
|
return Task {
|
||||||
|
|
||||||
while true {
|
var notCancelled: Bool = true
|
||||||
|
|
||||||
let dev = IoTSimulatorCore.getDev(devID: deviceID)!
|
let dev = IoTSimulatorCore.getDev(devID: deviceID)!
|
||||||
let env = IoTSimulatorCore.getEnv(name: envID)!
|
let env = IoTSimulatorCore.getEnv(name: envID)!
|
||||||
|
|
||||||
|
while notCancelled {
|
||||||
|
usleep(__useconds_t(dev.dutyCicle * 1000))
|
||||||
|
|
||||||
let message = dev.work(envrionment: env)
|
let message = dev.work(envrionment: env)
|
||||||
do {
|
do {
|
||||||
try success(message)
|
try success(message)
|
||||||
} catch {
|
} catch {
|
||||||
failure()
|
failure()
|
||||||
}
|
}
|
||||||
usleep(__useconds_t(dev.dutyCicle * 1000))
|
|
||||||
|
do {
|
||||||
|
try Task.checkCancellation()
|
||||||
|
} catch {
|
||||||
|
notCancelled = false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Bye, Bye, \(dev.deviceID)\n\n")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -63,3 +63,55 @@ import Testing
|
|||||||
sleep(15)
|
sleep(15)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test func stressLoop1() async throws {
|
||||||
|
|
||||||
|
let devices: Int = 1000
|
||||||
|
|
||||||
|
let env = PhysicalEnvironment("Delta")
|
||||||
|
let truth = PhysicalData(.Temperature, 22)
|
||||||
|
|
||||||
|
env.setPhysicalData(DataType.Temperature, truth)
|
||||||
|
|
||||||
|
IoTSimulatorCore.addEnv(environment: env)
|
||||||
|
|
||||||
|
let signKeyPath = "./Private/privateKey.pem"
|
||||||
|
|
||||||
|
let privateKey = try pem2key(filePath: signKeyPath)
|
||||||
|
|
||||||
|
for i in 0..<devices {
|
||||||
|
|
||||||
|
let dev: EdgeDevice = EdgeDevice(
|
||||||
|
deviceID: "EDG-00\(i)",
|
||||||
|
dataType: .Temperature,
|
||||||
|
disconnected: false,
|
||||||
|
location: Location3D(20, 10, 0),
|
||||||
|
dutyCicle: 200 + UInt.random(in: 1000...5000),
|
||||||
|
sensors: [
|
||||||
|
0: RealSensor(
|
||||||
|
sensorID: 0, sensorType: .Temperature, faulty: false, meanNoise: 1, stdNoise: 3,
|
||||||
|
quantizationBits: 3),
|
||||||
|
1: RealSensor(
|
||||||
|
sensorID: 1, sensorType: .Temperature, faulty: false, meanNoise: 1, stdNoise: 3,
|
||||||
|
quantizationBits: 3),
|
||||||
|
2: RealSensor(
|
||||||
|
sensorID: 2, sensorType: .Temperature, faulty: false, meanNoise: 1, stdNoise: 3,
|
||||||
|
quantizationBits: 3),
|
||||||
|
],
|
||||||
|
privateKey: privateKey
|
||||||
|
)
|
||||||
|
|
||||||
|
try IoTSimulatorCore.addDevice(location: "Delta", device: dev)
|
||||||
|
}
|
||||||
|
|
||||||
|
let _sleep = 15
|
||||||
|
|
||||||
|
for i in 0..<_sleep {
|
||||||
|
print("Hi, at \(i)s\n\n")
|
||||||
|
sleep(1)
|
||||||
|
}
|
||||||
|
print("NUKE EM ALLLLLLLLLL!!!!!\n\n")
|
||||||
|
IoTSimulatorCore.nukeAll()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user